1. js cross-origin operation: Add document. Domain = "y.com" to the two pages ";
2.In iframe, the parent page after operating the element can be used when using open('', '_top'folder or using partition parent.doc ument. Location. href =''
3. jsonp:
VaR url = 'HTTP: // test.yaolan.com/home/getj? Jsoncallback =? ';
$. Getjson (URL, function (data ){};
Back-end notes
Public void getj ()
{
String F = request. querystring ["jsoncallback"];
Response. Clear ();
Response. contenttype = "application/JSON ";
// Response. contenttype = "application/JavaScript ";
VaR JSON = new {A = "112", B = "224 "};
Response. write (string. format (@ "{0} ({1});", F, 1); // here, an error is always returned in JSON. Only simple characters are returned, unknown cause. Contenttype is suspected.
Response. End ();
}
A temporary method is automatically generated to replace "?" The temporary method and the result are returned after JSON concatenation. Otherwise, the callback method cannot be executed.
4. Window. Name solves cross-domain Problems
There is a cool man written: http://www.planabc.net/2008/09/01/window_name_transport/
Appendix 1: jquery getjson API: http://api.jquery.com/jQuery.getJSON/
Appendix 2:
Cross-origin principle of jquery jsonp
In fact, single jquery still cannot load data across domains. Because of the security settings of XMLHttpRequest, direct cross-origin is not allowed. Although jquery's jsonp can be cross-origin, it must be supported by the requested page. If the requested page ignores the parameters sent by jquery, it cannot cross-origin, in fact, the output page cannot be obtained.
The cross-origin principle of jquery jsonp is actually to use the script tag to load the cross-origin URL in the configuration object. before using the script tag to load, A new function will be registered on the client as the callback function for cross-domain page use, and then the function name will be replaced with the jsoncallback =? The following question mark shows the name of the callback function sent on the request page. The javascript code similar to "Callback Function Name (JSON data)" is output to execute the callback function. The parameter is JSON data. Similar to the proxy, jsonp requires the proxy page to output the JS Code that executes the callback function.
We know from the cross-origin of jquery that if the cross-origin page ignores the callback function and does not execute it, The JSON function output from the cross-origin page cannot be obtained, or even a script error may occur, because it uses scripts to load cross-origin pages.
Appendix 3: an article on JS cross-Origin
Http://wujiajun1020.iteye.com/blog/919293