---
title: "解决Javascript 使用xmlhttp提交中文乱码"
author: "llhdf"
date: "2009-11-09T13:54:24Z"
tags: []
slug: "javascript-xmlhttp"
draft: false
lastmod: "2009-11-09T13:54:24Z"
id: 512859
url: "https://llhdf.iteye.com/blog/512859"
---

```
function doUpdate(){

 try {
  
  var sel = getRightSel();
  var modeno = document.form1.modeno.value;
  var url = "UpdateDo.do?sel="+sel+"&modeno="+modeno;
  String.prototype.trim = function(){return this.replace(/\s/g,'');}
  
```

```
var url1 = encodeURI(url.trim());
  var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  xmlHttp.open("POST",url1,false);
     xmlHttp.send();
  var result= xmlHttp.responseText;
  var resulet1 = result.trim();
   
  if (resulet1=='false'){
   return false;
  }else{
   alert("修改成功");  
  }
  
 }catch(exception) {
  alert('<bean:message key="centerResume.serverShutDown"/>');
 }
 
 return false;
 
}
```

 使用 encodeURI 编码，使URL采用utf-8编码提交，否则中文将被改成其它编码格式。