用ActiveXObject中的send()方法传递值


var _xmlHttpRequestObj = new ActiveXObject("Microsoft.XMLHTTP");
        _xmlHttpRequestObj.open('POST',submiturl,true);
        _xmlHttpRequestObj.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
        //应用send传递参数需要设置Content-Type
        _xmlHttpRequestObj.onreadystatechange=postXmlHttpProcessPostChange;
        _xmlHttpRequestObj.send(sendcontext);


在send方法中可以传递 sendcontext="perm1=abcd"
在服务器端用String s = request.getParameter("perm1");来取出参数值,这里通常可以传递json数据。在页面可以将表单数据封装到js对象再序列化js对象成json数据,通过send方法传递到服务器段。就很容易的将js数据装换成javaBean了。

注意:用send方法传递参数必须设置setRequestHeader,其中charset=utf-8会将发送的数据编码成UTF-8的格式。这里很容器出现乱码,值得注意。

你可能感兴趣的:(JavaScript,应用服务器,json,Microsoft)