Jquery cannot use $. ajax solution in IE7

Source: Internet
Author: User

Find by checking the source code Copy codeThe Code is as follows: // Create the request object; Microsoft failed to properly
// Implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available
// This function can be overriden by calling jQuery. ajaxSetup
Xhr: function (){
Return window. ActiveXObject? New ActiveXObject ("Microsoft. XMLHTTP"): new XMLHttpRequest ();
},

The following is the jquery source code version declaration.Copy codeThe Code is 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: 17:34:21-0500 (Thu, 19 Feb 2009)
* Revision: 6246
*/

The result of printing "window. ActiveXObject" in an html file shows that IE6, IE7, and IE8 both return true,
The html source code for the test is (there is an index. jsp page under the same directory, and the content does not matter .)Copy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<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>
</Head>
<Body>
<Div> </div>
</Body>
</Html>

Scenario 1:
If the source code is not modified, the "success" prompt is displayed in IE6, but IE7 does not have any prompt, and no error prompt is displayed.
Scenario 2:
In the source code
Window. ActiveXObject? New ActiveXObject ("Microsoft. XMLHTTP"): new XMLHttpRequest ();
Change
Window. ActiveXObject? New XMLHttpRequest (): new XMLHttpRequest ();
In IE7, the "success" prompt is displayed, while IE6 prompts a js error. The details are probably "XMLHttpRequest object undefined".
In either case, FireFox prompts "success". The version is FireFox3.5.3, but other browsers do not know.
It can be seen that in IE7, you need to use new XMLHttpRequest () to initialize the ajax object, and IE6 uses new ActiveXObject ("Microsoft. XMLHTTP ")
However, the jQuery source code is not compatible with the IE7 initialization method, and the compatibility description on the official website is IE6 +.
Is it because I understand it wrong or what else? I hope you can give us some comments. jQuery is very useful, but I cannot ask the customer to use IE6, instead of IE7!
One more sentence:
The latest version of prototype 1.6.1 is also the same problem. Ajax. Request in IE7 does not work. You need to set the source code to around 1130 lines.Copy codeThe Code is 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;
},

Modify the part of the comment.
In this way, you can use this ajax request method in IE7.
But let's take a rough look. The ajax initialization here is first created using new XMLHttpRequest (), that is,
If I do not modify it, IE7 should also work.
Note: In the end, the IE7 compatibility method is found on the network.
The above is the result of my research today. I am confused about how to implement jQuery, which is fully compatible with IE6, IE7, and IE8 (does not affect FireFox, etc)
If the conclusion is:
It can be seen that in IE7, you need to use new XMLHttpRequest () to initialize the ajax object, and IE6 uses new ActiveXObject ("Microsoft. XMLHTTP ")
How can we explain prototype?
I am confused. I hope you can give me some advice!
Just now I searched for the method for creating XMLHttpRequest, and finally changed the source code
Return window. XMLHttpRequest? New XMLHttpRequest (): window. ActiveXObject? New ActiveXObject ("Microsoft. XMLHTTP"): new XMLHttpRequest ();
Then IE6 \ 7 \ 8 and FF can be run.
Finally, it is 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.