在Internet Explorer中的跨域POST请求阿贾克斯Explorer、Internet、阿贾克斯、POST

由网友(男人必须傲↑)分享简介:我使用jQuery 1.7.2,并希望做一个POST请求到另一个域。它必须是一个POST请求。但这在Internet Explorer中无法正常工作(我试过IE9);它适用于所有其他浏览器。我有这样的脚本:<脚本>jQuery.support.cors = TRUE;jQuery的(函数(){$阿贾克斯(...

我使用jQuery 1.7.2,并希望做一个POST请求到另一个域。它必须是一个POST请求。但这在Internet Explorer中无法正常工作(我试过IE9);它适用于所有其他浏览器。

我有这样的脚本:

<脚本> jQuery.support.cors = TRUE; jQuery的(函数(){     $阿贾克斯({         跨域:真正的,         缓存:假的,         键入:POST,         网址:HTTP://someotherdomain/test.php,         数据: {},         成功:函数(DA){             的console.log(JSON.stringify(DA))         },         错误:函数(jqxhr){             的console.log('故障')             的console.log(JSON.stringify(jqxhr))         },         数据类型:JSON     }); }); < / SCRIPT>

我找回了错误:

{readyState的0状态:0,状态文本:错误:拒绝访问 r。 N}

我的PHP文件看起来是这样的:

< PHP 标题(访问控制 - 允许 - 产地:*'); 标题(访问控制 - 允许 - 方法:GET,POST,DELETE,PUT,OPTIONS'); 回声json_de code(阵列('成功'=>'是')); 如何把Internet Explorer设置在桌面上

解决方案

要支持IE&LT CORS; 10,您必须修改AJAX方法使用XDomainRequest对象。这个插件会为你: https://github.com/jaubourg/ajaxHooks

I'm using jQuery 1.7.2 and would like to make a POST request to another domain. It must be a POST request. But this does not work in internet explorer (I tried on IE9); it works on all other browsers.

I have this script:

<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>

I get back the error:

{"readyState":0,"status":0,"statusText":"Error: Access denied.rn"}

My PHP file looks like this:

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

解决方案

To support CORS in IE < 10, you must modify the ajax method to use the XDomainRequest object. This plugin does it for you: https://github.com/jaubourg/ajaxHooks

阅读全文

相关推荐

最新文章