Example
AjaxPage ("yy", "http://static.111cn.net/js/jquery-1.8.0.min.js ");
Function ajaxPage (sId, url)
{
Var oXmlHttp = getHttpRequest ();
OXmlHttp. onreadystatechange = function ()
{
// 4 indicates that the data has been sent
If (oXmlHttp. readyState = 4)
{
// 0 indicates the local access, 200 indicates that the access to the server is successful, and 304 indicates that the access to the cache is not modified.
If (oXmlHttp. status = 200 | oXmlHttp. status = 0 | oXmlHttp. status = 304)
{
IncludeJS (sId, oXmlHttp. responseText );
}
}
}
OXmlHttp. open ("GET", url, false); // true indicates asynchronous loading (that is, other code can be run while sending ajax) false: // synchronous loading (other code cannot be executed when loading );
OXmlHttp. send (null );
}
Function getHttpRequest ()
{
If (window. ActiveXObject) // IE
{
Return new ActiveXObject ("MsXml2.XmlHttp ");
}
Else if (window. XMLHttpRequest) // Others
{
Return new XMLHttpRequest ();
}
}
Result error
Cross-source requests intercepted: same-origin policy prohibits reading remote resources that are located in the http://static.111cn.net/js/jquery-1.8.0.min.js. (Cause: the CORS header lacks 'access-Control-Allow-origin ').
Cause analysis
The error report above shows that cross-source requests cannot be implemented through ajax. Therefore, you can directly call the content in the current domain or directly use jsinclude.
Solution
AjaxPage ("yy", "http://static.111cn.net/js/jquery-1.8.0.min.js ");
Modify
AjaxPage ("yy", "/js/jquery-1.8.0.min.js");
Of course, if you can modify the page's direct loading <script language = "javascript" src = "js/v4/jquery. js"> </script> method, there will be no problem.