Research on ext to discover Ajax cross-origin implementation

Source: Internet
Author: User
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 ′}
]
};
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.