Skip to the content.

如何解决跨域问题


JSONP:

<script>
    function createJs(sUrl){

        var oScript = document.createElement('script');
        oScript.type = 'text/javascript';
        oScript.src = sUrl;
        document.getElementsByTagName('head')[0].appendChild(oScript);
    }

    createJs('jsonp.js');

    box({
       'name': 'test'
    });

    function box(json){
        alert(json.name);
    }
</script>

CORS

通过修改document.domain来跨子域

使用window.name来进行跨域

使用HTML5中新引进的window.postMessage方法来跨域传送数据

如何解决跨域问题?