What is Ajax? The interaction Model (flow) of Ajax? What is the difference between synchronous and asynchronous? Ajax cross-domain solution?
What is Ajax: Asynchronous JavaScript and XML
Ajax is used to create fast web technologies
Partial updates to the page via asynchronous updates via a small number of data interactions in the background and the server Venus
Sync: Wait for the page to finish before continuing.
Async: page continuation and process processing possible reply
Exchange process
1, create XHR
2,open open asynchronous channel, set asynchronous request true for asynchronous request
3,send sending data
4, Judge Readystate==4; HTTP requests are successful between 200,300 or 304 data requests
Cross-Domain Technology
What is a cross-domain
Can communicate: The same domain name, different files under the same domain name
Can not communicate: 1, same domain name, different ports
2, same domain name, different protocol.
3, the domain name and the corresponding IP
4,http://www.a.com/a.js
Http://script.a.com/b.js primary domain is the same, subdomain is different
5,http://www.a.com/a.js
Http://a.com/b.js same domain name, different level two domain name (IBID.)
6,http://www.cnblogs.com/a.js
Http://www.a.com/b.js different domain names
1.document.domain+iframe settings (primary domain is the same, subdomain is not the same)
The a.html on the wwww.a.com
Document.domain+ifame
document.domian= ' a.com ';
var ifr=document.createelement (' iframe ');
ifr.src= ' http://script.a.com/b.html ';
Ifr.style.display= ' None ';
Document.body.appendChild (IFR);
Ifr.onload=function () {
var doc = Ifr.contentdocument | | Ifr.contentWindow.document;
Manipulating the b.html here.
Alert (Doc.getelementsbytagname ("H1") [0].childnodes[0].nodevalue);
}
The b.html on the script.a.com
Document.domain= ' a.com '
2,jsonp (ison+padding) box ({name:ve;}), write function in another file via callback function
function Createjs (sURL) {
var oscript=documnet.createelement (' script ');
Oscript.type= ' Text/javascript ';
Oscript.src=surl;
document.getElementsByTagName (' Heade ') [0].appendchild (Oscript);
}
Createjs (' Jsonp.js?callback=box ');
function box (JSON) {
alert (json.name);
}
1350*3=405
3,location.hash
Parent.location.hash
yyy.html#
Parent.location.hash=self.location.hash;
<iframe src= ' xxx.php#key1=value1&key2=value2 ' ></iframe>
IE, chrome security mechanism can not modify parent.location.hash, to take advantage of an intermediary cnblogs domain proxy iframe
4,window.name
Name is a property of a global/window object in the browser environment, and the property value of name remains unchanged when a new page is loaded in the frame.
By loading a resource in the IFRAME, the target page sets the Name property of the frame. This Name property value can be obtained to access the information sent by the Web service.
But the Name property is accessible only to frames of the same domain name. This means that in order to access the Name property, when the Remote Web service page is loaded, the frame must be navigated back to the original domain.
The same-origin policy still prevents other frames from accessing the Name property. Once the Name property is obtained, the frame is destroyed
There's an agent interface.
There are three page pages
1,a.com/app.html; Application Page
2,a.com/proxy.html Agent File
3,b.com/data.html data page
5,HTML5 PostMessage
Code in the A.com/index.html
<iframe id= ' IFR ' src= ' b.com/index.html ' ></iframe>
Window.onload=function () {
var Ifr=document.getelementbyid (' IFR ');
var targetorigin= ' http://b.com ';
Ifr.contentWindow.postMessage (' I was there ', Targetorigin)
}
Code in the B.com/index.html
Window.addeventlistener (' message ', function (event) {
if (event.origin== ' http://a.com ') {
alert (event.data);
}
},false);
What is Ajax? The interaction Model (flow) of Ajax? What is the difference between synchronous and asynchronous? Ajax cross-domain solution?