奈飞|Ajax跨域请求的两种实现方式( 三 )


            delete FrameHttp.request_map[data.key

        
    


export default FrameHttp
export { FrameHttpCmd 

然后域名A中的/util/ajaxrequest页面处理请求:
import React { Component  from 'react'
import { FrameHttpCmd  from '../../../common_js/web_frame/FrameHttp'
import jquery from '../../../common_js/jquery.min'

class AjaxRequest extends Component {
    constructor(props) {
        super(props)

        this.onMessage = this.onMessage.bind(this)
    

    onMessage(e) {
        const { cmd data key cookie  = e.data
        if (cmd == FrameHttpCmd.REQUEST) {
            // console.log(key data)
            console.log(document.cookie)
            jquery.ajax({
                ...data
                success: (data)=>{
                    window.parent.postMessage({
                        cmd: FrameHttpCmd.REQUEST_CALLBACK
                        key
                        success: data
                     '*')
                
                error: ()=>{
                    window.parent.postMessage({
                        cmd: FrameHttpCmd.REQUEST_CALLBACK
                        key
                        error: 'error'
                     '*')
                
            )
        
    

    componentDidMount() {
        window.parent.postMessage({
            cmd: FrameHttpCmd.INIT
         '*')