Home >Backend Development >PHP Tutorial >How to solve Ajax submission garbled code under IE
This article mainly brings you a quick solution to Ajax submission garbled code under IE. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor to take a look, I hope it can help everyone.
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 does not seem to work, o(︶︿︶)o Alas, still You are reliable~~
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
Related recommendations:
Ajax submits the Form form page and will still refresh j solution
Ajax form submission and file upload example code
The above is the detailed content of How to solve Ajax submission garbled code under IE. For more information, please follow other related articles on the PHP Chinese website!