This time I will show you how to deal with garbled codes submitted by Ajax under IE. What are the precautions for dealing with garbled codes submitted by Ajax under IE. The following is a practical case, let's take a look.
Haha, after trying so many things, encodeURIComponent still works! ! ! !
Add a protective measure to the position of Chinese characters: encodeURIComponent(parentid)
function loadCity(parentid) { var city = '${hotel.city}'; $.ajax({ url: './listCity.jspx?prov='+ encodeURIComponent(parentid), type: 'GET', dataType: 'JSON', timeout: 5000, error: function() { alert('加载城市列表失败!'); }, success: function(msg) { $("#city").empty(); $.each(eval(msg), function(i, item) { if(item.city ==city){ $("<option value='" + item.city + "' selected = 'selected'>" + item.city + "</option>").appendTo($("#city")); }else{ $("<option value='" + item.city + "'>" + item.city + "</option>").appendTo($("#city")); } }); } }); }
Another method of adding contentType mentioned on the Internet seems to be irrelevant Use, o(︶︿︶)o Oh, it’s better to rely on yourself~~
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Ajax+mysq realizes the three-level linkage list of provinces and municipalities
Ajax transmits Json and xml data Detailed explanation of the steps (with code)
The above is the detailed content of How to deal with Ajax submission garbled code under IE. For more information, please follow other related articles on the PHP Chinese website!