Home  >  Article  >  Web Front-end  >  How to solve the problem that jquery ajax is not compatible with ie8

How to solve the problem that jquery ajax is not compatible with ie8

藏色散人
藏色散人Original
2021-01-05 09:13:482378browse

The solution to jquery ajax being incompatible with ie8: first open the corresponding code file; then use JSON format to request data, with code statements such as "{foo:["bar1", "bar2"]}".

How to solve the problem that jquery ajax is not compatible with ie8

The operating environment of this tutorial: Dell G3 computer, Windows 7 system, jquery1.10.0&&ie8 version.

Recommended: "javascript basic tutorial""jquery video tutorial"

About the solution to jQuery's AJAX incompatibility with IE

When using jQuery's AJAX: get method to detect whether data exists, you will find that IE will be incompatible.

When using the AJAX:post method, the correct results can appear when using Chrome/FireFox/IE, but when using the AJAX:get method, IE cannot return the correct results.

Could it be that the data exceeds the length limit of the get method? This is impossible. I only transferred a little bit of data in total. exclude.

Some netizens on the Internet said that it is a problem with IE cache. Just add a random number after the request data, such as adding the time number new Date().getTime().

I have added random numbers in the previous code, and using "Math.random()" does not work. Is it more reliable to use time?

Then try changing it to getting the time. After adding "new Date().getTime()" to the parameter, it still doesn't work after repeated testing. It's really puzzling! This error is also eliminated.

After repeatedly checking the manual, I found that the requested data format still has a JSON format, such as {foo:["bar1", "bar2"]}, and then I wrote it in this format, and it really returned the correct query results. I really didn't know IE still had this requirement. (End)

Previous format:

type: "get",
data: "bid="+my_bid+"&name_cn="+name_cn+"&timeStamp="+new Date().getTime(),

Improved format:

type: "get",
data: {'bid':my_bid,'name_cn':name_cn,'timeStamp':new Date().getTime()},

is described in the jQuery manual:

data Object,String

Send to server The data. Will be automatically converted to request string format. Appended to the URL in GET requests.

See the processData option description to disable this automatic conversion. Must be in Key/Value format.

If it is an array, jQuery will automatically correspond to the same name for different values. For example, {foo:["bar1", "bar2"]} is converted to "&foo=bar1&foo=bar2".

Code snippet:

var siteUrl="http://blog.sina.com.cn/cnwyt"; 
jQuery.ajax({
type: "get",
url: siteUrl+"cosmetics/product/ajax_check?",
//data: "bid="+my_bid+"&name_cn="+name_cn+"&timeStamp=" + new Date().getTime(),
data: {'bid':my_bid,'name_cn':name_cn,'timeStamp':new Date().getTime()},
dataType: 'json',
error: function (err) { alert('网络故障,请与管理员联系!') },
success: function (message) {
if(message!=false){
//ture的代码
}else{
//false的代码
}
});

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of How to solve the problem that jquery ajax is not compatible with ie8. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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