demo
var invocation = new XMLHttpRequest();
var url = 'http://bar.other/resources/post-here/';
var body = '<?xml version="1.0"?><person><name>Arun</name></person>';
function callOtherDomain(){
if(invocation)
{
invocation.open('POST', url, true);
invocation.setRequestHeader('X-PINGOTHER', 'pingpong');
invocation.setRequestHeader('Content-Type', 'application/xml');
invocation.onreadystatechange = handler;
invocation.send(body);
}
}
// ......

本文展示了一个使用XMLHttpRequest进行跨域POST请求的JavaScript代码示例。该示例向目标URL发送XML格式的数据,并设置了特定的请求头以实现跨域通信。

4499

被折叠的 条评论
为什么被折叠?



