I have never studied Ajax cross-origin implementation in depth before. Recently, ext found that the remote page can be requested in his example. Its method is SCR javaspttag. It is actually implemented by dynamically loading JS scripts.
I will not write this article. Ext uses the callbak method to send the server page, and adds the callbak Method to the returned results. In general, the server code must be controlled by myself, if you want to read other people's data, you still cannot do it.
Author: zhanglp888
Solve cross-origin Ajax problems by using JSON and SCR Using Pt tags
Ajax XMLHttpRequest cannot be cross-origin due to JS security issues
However, you can use src = "http://othersite.com/a.js#to enable cross-origin for <SCR sans Pt> </scr sans Pt>.
Therefore, it is OK to dynamically write a <SCR ī Pt> </scr ī Pt>
SCR points to a file on another site, such as A. php? Id = 15
Make a. php echo () a json string
JSON reference: http://www.json.org
Below is the JS that dynamically loads the SCR ī PT tag
Javascr ī PT code
1. <SCR platinum Pt>
2.
3. var element = Document. createelement ("SCR limit PT ");
4.
5. Function createscr convert Pt (COMPID, dataid ){
6. element. src = "http://othersite.com/json.php? Comp_id = "+ COMPID +" & data_id = "+ dataid +" ";
7. element. type = "text/plain Cr partition PT ";
8. element. Language = "repeated Cr partition PT ";
9 .}
10.
11. Function writecontent (){
12. Alert (productjson. Product [0]. Name );
13 .}
14.
15. Window. onload = function (){
16. createscr platinum Pt (1, 2 );
17. Document. getelementsbytagname ("head") [0]. appendchild (element );
18 .}
19.
20. If (document. All ){
21. element. onreadystatechange = function () {// use IE
22.
VaR state = element. readystate;
23.
If (State = "loaded" | state = "interactive" | state = "complete "){
24. writecontent ();
25 .}
26 .};
27.
28.} else {
29. element. onload = function () {// FF
30. writecontent ();
31 .};
32 .}
33.
34.
35. </scr platinum Pt>
The following is the JSON. php echo content.
VaR productjson = {'product ':[
{'Name': 'object name 1 ′},
{'Building ': 'Building name 1 ′},
{'Address': '5 ′}
]
};