Internet Explorer中跨域POST请求ajax

2024-04-03

我正在使用 jQuery 1.7.2,并且想向另一个域发出 POST 请求。它必须是 POST 请求。但这确实无法在 Internet Explorer 中工作(我在IE9上试过);它适用于所有其他浏览器。

我有这个脚本:

<script>
jQuery.support.cors = true;

jQuery(function() {
    $.ajax({
        crossDomain : true,
        cache: false,
        type: 'POST',
        url: 'http://someotherdomain/test.php',
        data: {},
        success: function(da) {
            console.log(JSON.stringify(da))
        },
        error: function(jqxhr) {
            console.log('fail') 
            console.log(JSON.stringify(jqxhr))
        },
        dataType: 'json'
    });
});
</script>

我得到错误:

{"readyState":0,"status":0,"statusText":"Error: Access denied.\r\n"}

我的 PHP 文件如下所示:

<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, DELETE, PUT, OPTIONS');
echo json_decode(array('success' => 'yes'));

Internet Explorer(包括IE9)不支持CORS http://en.wikipedia.org/wiki/Cross-origin_resource_sharing。您必须代理所有跨域请求(发布到同一域上的 PHP 脚本,该脚本使用 curl 重新发布您的查询并返回响应)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Internet Explorer中跨域POST请求ajax 的相关文章

随机推荐