jquery cannot use the $.ajax solution under IE7 _jquery

Source: Internet
Author: User
By looking at the source discovery
Copy Code code as follows:

Create the Request object; Microsoft failed to properly
Implement the XMLHttpRequest in IE7 and so we use the ActiveXObject when it is available
This function can is overriden by calling Jquery.ajaxsetup
Xhr:function () {
return window. ActiveXObject? New ActiveXObject ("Microsoft.XMLHTTP"): New XMLHttpRequest ();
},

The following is a version of the jquery source statement
Copy Code code as follows:

/*
* JQuery JavaScript Library v1.3.2
* http://jquery.com/
*
* Copyright (c) 2009 John Resig
* Dual licensed under the MIT and GPL licenses.
* Http://docs.jquery.com/License
*
* date:2009-02-19 17:34:21-0500 (Thu, Feb 2009)
* revision:6246
*/

print "Window" through an HTML. The result of the ActiveXObject "is that IE6, IE7, and IE8 are all returned true,
Test the HTML source code for (the same directory has a name index.jsp page, the content does not matter.) )
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<script type= "Text/javascript" src= "Javascript/jquery.js" ></script>
<script type= "Text/javascript" >
$ (function () {
$.ajax ({
URL: "Index.jsp",
Success:function () {alert ("Success")},
Error:function () {alert ("Error")}
});
$ ("div"). Append ("<font color= ' Red ' >window.) Activexobject:</font> ");
$ ("div"). Append (window. ActiveXObject? " True ': ' false ');
Alert (typeof (New XMLHttpRequest ()));
Alert (typeof new ActiveXObject ("msxml2.xmlhttp.4.0"));
Alert (typeof new ActiveXObject ("Msxml2.xmlhttp"));
Alert (typeof new ActiveXObject ("Microsoft.XMLHTTP"));
});
</script>
<body>
<div></div>
</body>

Situation One:
Do not modify the source code, then the IE6 can be pop-up "success" hint, and IE7 without any hint, even the wrong hint.
Situation Two:
The source in the
Window. ActiveXObject? New ActiveXObject ("Microsoft.XMLHTTP"): New XMLHttpRequest ();
Amended to
Window. ActiveXObject? New XMLHttpRequest (): New XMLHttpRequest ();
Then the IE7 is pop-up "success" prompts, and IE6 is prompted JS error, the details of the "XMLHttpRequest object is not defined"
In both cases Firefox can normally prompt "success", version is FireFox3.5.3, other browsers do not know.
This shows that the Ajax object needs to be initialized with the new XMLHttpRequest () in IE7, and IE6 uses the new ActiveXObject ("Microsoft.XMLHTTP")
However, the jquery source is not compatible with the IE7 initialization method, while the official web compatibility instructions are ie6+.
Did I understand the mistake or something else? I hope you give some advice, jquery very good, but I can not ask customers must use IE6, and give up IE7 Ah!
One last sentence:
Prototype the latest version of 1.6.1 is also the same problem IE7 under the ajax.request is not effective, need to be the source of the 1130 line of
Copy Code code as follows:

var Ajax = {
Gettransport:function () {
Return Try.these (
function () {return new XMLHttpRequest ()},
function () {return new ActiveXObject (' Msxml2.xmlhttp ')},
function () {return new ActiveXObject (' msxml2.xmlhttp.4.0 ')},
function () {return new ActiveXObject (' Microsoft.XMLHTTP ')}
) || False
},

To make changes, that part of the annotation is the modification that needs to be added.
This allows the Ajax request method to be used under IE7.
But we have a rough look, this AJAX initialization is to use the new XMLHttpRequest () first to create, that is to say,
If I do not change the words IE7 should also be able to.
Note: The last more than one IE7 compatibility method is a search on the web
The above is my research results today, make me very confused, in the end this IE6, IE7 and IE8 fully compatible jquery How to achieve (can not affect Firefox, etc. oh)
If the conclusion is:
This shows that the Ajax object needs to be initialized with the new XMLHttpRequest () in IE7, and IE6 uses the new ActiveXObject ("Microsoft.XMLHTTP")
So, how do you explain that in prototype?
I have been confused, I hope you can guide twos!
Just then searched for the XMLHttpRequest of the creation method, and finally the source code revision to
return window. XMLHttpRequest? New XMLHttpRequest (): window. ActiveXObject? New ActiveXObject ("Microsoft.XMLHTTP"): New XMLHttpRequest ();
Then both IE6\7\8 and FF can be run.
Finally, it was solved.
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.