zoukankan      html  css  js  c++  java
  • js用escape()轻松搞定ajax post提交汉字的乱码问题

     1<script language="javascript">  
     2 function get(id){return document.getElementById(id).value}
     3   function setting()
     4   {
     5     var xmlHttp;
     6  if(window.ActiveXObject)
     7  {
     8    xmlHttp=new ActiveXObject("Microsoft.XMLHttp")
     9  }
    else{
    10   xmlHttp=new XMLHttpRequest();
    11 }

    12 xmlHttp.onreadystatechange=function()
    13 {
    14    if(xmlHttp.readyState==4)
    15    {
    16       if(xmlHttp.status==200)
    17    {
    18       alert("成功!")
    19    }
    else{
    20       alert(xmlHttp.status)
    21    }

    22    }

    23    }

    24 var url="action.asp?action=setting&rnd="+Math.random()
    25 xmlHttp.open("post",url,true)
    26 var sendDate ="title="+escape(get("title"))+"&conn_way="+escape(get("conn_way"))+"&DatabaseName="+escape(get("DatabaseName"))+"&SqlUsername="+escape(get("SqlUsername"))+"&SqlPassword="+escape(get("SqlPassword"))+"&SqlLocalName="+escape(get("SqlLocalName"))+"&pg_size="+escape(get("pg_size"))+"&adminID="+escape(get("adminID"))+"&adminPWD="+escape(get("adminPWD"));
    27 xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    28 xmlHttp.send(sendDate)
    29  }

    30</script>

  • 相关阅读:
    async await promise写法
    nginx自动启动脚本
    nginx源码编译安装
    PHP源码编译安装
    MySQL修改root密码的多种方法
    PKG_CONFIG_PATH变量 与 ld.so.conf 文件
    confluence5.65+CentOS+mysql安装破解
    nigos core 安装配置
    cacti+CentOS6.5
    Linux+mysql+apache+php
  • 原文地址:https://www.cnblogs.com/smallfa/p/1623535.html
Copyright © 2011-2022 走看看