0

I'm trying to write a plugin. I can not use any libraries or frameworks. At any website (domain) I would like to start a script from my own domain.

For example: In the code of the website under domain A I put a code starting the script from domain B

<script src="http://domain-b.com/myscript.js" type="text/javascript"></script>

The code of JavaScript (myscript.js)

type = 'GET';
url = 'http://domain-b.com/echojson.php';
data = ‘var1=1&var2=2’;

_http = new XMLHttpRequest();

_http.open(type, url + '?callback=jsonp123' + '&' + data, true);
_http.onreadystatechange = function() {
      alert(‘Get data: ’ + _http.responseText);
}
_http.send(null);

Script from http://domain-b.com/echojson.php always gives the answer:

jsonp123({answer:”answer string”});

But in a JavaScript console I see an error (200) and AJAX doesn’t get anything.

4

2 回答 2

0

像 LAB、yep/nope 或Frame.js这样的脚本加载器旨在绕过同源策略。他们加载一个脚本文件,因此请求的文件必须如下所示:

response = {answer:”answer string”};
于 2012-04-27T15:06:46.073 回答
0

如果您像在此处发布的那样使用您的代码,则它不起作用,因为您正在为data变量使用撇号!

于 2012-04-27T15:07:58.600 回答