今天在使用jQuery的ajax时出现了中文乱码问题:
刚开始使用的是get:
function changeVmList(){ var productName = document.getElementById("productName").value; $.get( "<%=basePath%>assitanceAction.do?method=getVmCombo", {productName:productName}, function(vmCombo){ document.getElementById('vmName').innerHTML = ""; //document.getElementById('vmName').innerHTML = vmCombo; var temp=vmCombo.split(','); for(var i=0;i<temp.length;i++){ var tempOption = document.createElement("option"); tempOption.value = temp[i]; tempOption.innerHTML = temp[i]; document.getElementById('vmName').appendChild(tempOption); } }); }
?发现到后台中文参数是乱码,加上encodeURIComponent 发现到后台解析不出来,到Action中依然是%E4%BA%A7%E5%93%812之类的转码后的值。。。。。!
后来将发送方式改为post搞定。
function changeVmList(){ var productName = document.getElementById("productName").value; $.post( "<%=basePath%>assitanceAction.do?method=getVmCombo", {productName:productName}, function(vmCombo){ document.getElementById('vmName').innerHTML = ""; //document.getElementById('vmName').innerHTML = vmCombo; var temp=vmCombo.split(','); for(var i=0;i<temp.length;i++){ var tempOption = document.createElement("option"); tempOption.value = temp[i]; tempOption.innerHTML = temp[i]; document.getElementById('vmName').appendChild(tempOption); } }); }?