开发者

Can I using cross-site XmlHttpRequest in Itunes LP environment?

开发者 https://www.devze.com 2022-12-25 10:55 出处:网络
Itunes is based on Webkit platform and we can\'t use cross-site XmlHttpRequest in JavaScript because of security policy. But, as a exception, we can do that with a special header.

Itunes is based on Webkit platform and we can't use cross-site XmlHttpRequest in JavaScript because of security policy. But, as a exception, we can do that with a special header. Here is source code and I did it successfully in Safari:

var url = 'http://mysite.net/canvas.php';   

var mybody = "<?xml version='1.0' charset='utf-8'?><person><name>Arun</name></person>";
var http = new XMLHttpRequest();

http.open("POST", url, true);   
http.setRequestHeader("X-PINGOTHER", "pingpong");
http.setRequestHeader('Content-Type', 'application/xml');

http.setRequestHeader("Content-length", mybody.length);
http.setRequestHeader("Connection", "close");   
http.send(mybody);

I sent xml data to my server and get return开发者_运维技巧 response successfully in Safari browser but i can't do it in iTunes LP environment. So what is the problems?


I don't know what iTunes LP environment is but normally, if you need to do cross site scripting you'd use JSONP. Look into that. I'm sure you can find loads of examples.


JSONP is good option, but in order to do that, you need to create the service to provide the feature of JSONP. But, you not may the owner for that.

You can go with proxy to send the XmlHttpRequest which you can use Flash as proxy. You can find better example here

0

精彩评论

暂无评论...
验证码 换一张
取 消