如何在IE CORS中发送POST数据(使用XDomainRequest) [英] How to Send POST data in IE CORS ( with XDomainRequest)
本文介绍了如何在IE CORS中发送POST数据(使用XDomainRequest)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在寻找一个简单的例子,如何在IE中的跨域请求中发送POST数据(使用XDomainRequest对象)。
I've been looking for a simple example of how to send POST data in a cross domain request in IE (with the XDomainRequest object).
已能够进行简单的POST请求,但无法向其中添加POST数据。
I've been able to make a simple POST request, but haven't been able to add POST data to it.
任何帮助,请感谢!
推荐答案
尝试这样:
var xdr;
function err() {
alert('Error');
}
function timeo() {
alert('Time off');
}
function loadd() {
alert('Response: ' +xdr.responseText);
}
function stopdata() {
xdr.abort();
}
xdr = new XDomainRequest();
if (xdr) {
xdr.onerror = err;
xdr.ontimeout = timeo;
xdr.onload = loadd;
xdr.timeout = 10000;
xdr.open('POST','http://example.com');
xdr.send('foo=12345');
//xdr.send('foo=<?php echo $foo; ?>'); to send php variable
} else {
alert('XDR undefined');
}
服务器端(php):
header('Access-Control-Allow-Origin: *');
if(isset($HTTP_RAW_POST_DATA)) {
parse_str($HTTP_RAW_POST_DATA); // here you will get variable $foo
if($foo == 12345) {
echo "Cool!"; // This is response body
}
}
这篇关于如何在IE CORS中发送POST数据(使用XDomainRequest)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文