Home > Web Front-end > JS Tutorial > Jquery cannot use $.ajax solution under IE7_jquery

Jquery cannot use $.ajax solution under IE7_jquery

WBOY
Release: 2016-05-16 18:42:08
Original
1470 people have browsed it

By viewing the source code, I found

Copy the code The 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 version statement of this jquery source code
Copy code The 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: 2009-02-19 17:34:21 -0500 (Thu, 19 Feb 2009)
* Revision: 6246
*/

By a From the result of html printing "window.ActiveXObject", we can know that IE6, IE7 and IE8 all return true.
The tested html source code is (there is a page named index.jsp in the same directory, the content does not matter.)
Copy code The code is as follows:





Insert title here







Scenario 1:
If the source code is not modified, the "success" prompt will pop up in IE6, but there is no prompt in IE7, not even an error prompt.
Case 2:
Change
window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
in the source code to
window.ActiveXObject ? new XMLHttpRequest( ): new XMLHttpRequest();
The "success" prompt pops up in IE7, but IE6 prompts a js error, the details are probably "XMLHttpRequest object is not defined"
In both cases, FireFox can prompt normally." success", the version is FireFox3.5.3, other browsers don't know.
It can be seen that IE7 needs 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 IE7's initialization method, and the official website The compatibility note is IE6.
Did I understand it wrong, or something else? I hope you can give me some advice. jQuery is easy to use, but I can’t require customers to use IE6 instead of IE7!
One last sentence:
The latest version of prototype 1.6.1 also has the same problem. Ajax.Request under IE7 has no effect. You need to change the source code around 1130 lines
Copy code The 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;
},

Make changes. The commented part is the changes that need to be added.
This way you can use this ajax request method under IE7.
But if you take a quick look, the ajax initialization here is created first using new XMLHttpRequest(), that is to say,
If I don’t modify it, IE7 should be able to do it.
Note: The last one-sentence IE7 compatibility method was found on the Internet
The above is the result of my research today, which makes me very confused. What is the purpose of jQuery that is fully compatible with IE6, IE7 and IE8? How to implement it (cannot affect FireFox, etc.)
If the conclusion is:
It can be seen that IE7 needs to use new XMLHttpRequest() to initialize the ajax object, and IE6 uses new ActiveXObject("Microsoft.XMLHTTP")
So how do you explain it in the prototype?
I am confused, I hope you can give me some advice!
I just searched again about the creation method of XMLHttpRequest, and finally modified the source code to
return window.XMLHttpRequest? new XMLHttpRequest() : window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest() ;
Then both IE678 and FF can run.
Finally solved.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template