Chinaunix首页 | 论坛 | 博客
  • 博客访问: 755433
  • 博文数量: 119
  • 博客积分: 137
  • 博客等级: 少校
  • 技术积分: 1582
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-28 16:39
文章分类

全部博文(119)

文章存档

2017年(3)

2016年(7)

2014年(1)

2013年(8)

2012年(20)

2011年(27)

2010年(53)

分类: 系统运维

2012-05-24 18:09:10

1. 登陆页面自动提交,提交后无刷新
2. 显示提交是否成功
3. 显示服务器返回结果



  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
  2. <html>
  3.  <head>
  4.   <title> New Document </title>
  5.   <meta name="Generator" content="EditPlus">
  6.   <meta name="Author" content="">
  7.   <meta name="Keywords" content="">
  8.   <meta name="Description" content="">
  9.  </head>

  10. <script type="text/javascript">


  11. var xmlHttp = false;
  12. try {
  13.     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  14. } catch (e) {
  15.     try {
  16.          xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  17.     } catch (e2) {}
  18. }

  19. if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
  20.     try {
  21.         xmlHttp = new XMLHttpRequest();
  22.     } catch(e3){
  23.         xmlHttp = false;
  24.     }
  25. }


  26. function createKbQueryString(){

  27.     var phone = document.getElementsByName("phone").value;
  28.     var macaddress = document.getElementsByName("macaddress").value;
  29.     var additional_1 = document.getElementsByName("additional_1").value;
  30.     var additional_2 = document.getElementsByName("additional_2").value;
  31.     var additional_3 = document.getElementsByName("additional_3").value;
  32.     var validate = document.getElementsByName("validate").value;
  33.   
  34.     KbqueryString = "phone=" + phone + "&macaddress=" + macaddress + "&additional_1=" + additional_1 + "&additional_2=" + additional_2 + "&additional_3=" + additional_3 + "&validate=" + validate;
  35.     return KbqueryString;
  36. }

  37. function KbRequestQueryPOST(){
  38.         var url = "";
  39.         var KbqueryString = createKbQueryString();        
  40.         xmlHttp.open("post",url,true);
  41.         xmlHttp.onreadystatechange = handleStateChangeKb;
  42.         xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  43.         xmlHttp.send(KbqueryString);
  44. }

  45. function handleStateChangeKb(){
  46.         if(xmlHttp.readyState == 4){
  47.                 var responseSpanKb = document.getElementById("serverResponseKb");
  48.                 responseSpanKb.innerHTML = "请稍等…";
  49.                 if(xmlHttp.status == 200){
  50.                         var ResponseKbJSON = unescape(xmlHttp.responseText);
  51.                         switch (ResponseKbJSON){
  52.                            case "Bad1":
  53.                                  responseSpanKb.innerHTML = "HTTP Code:" + xmlHttp.status + " 内容不能为空";
  54.                                  document.getElementById("offerId1").innerHTML = ResponseKbJSON;
  55.                                  break
  56.                            case "Bad2":
  57.                                  responseSpanKb.innerHTML = "HTTP Code:" + xmlHttp.status + " 可能所填不全,或接口问题,未通过校验";
  58.                                  document.getElementById("offerId1").innerHTML = ResponseKbJSON;
  59.                                  break
  60.                            case "Bad3":
  61.                                  responseSpanKb.innerHTML = "HTTP Code:" + xmlHttp.status + " 获取远程数据出错(可能是不能连接外网)";
  62.                                  document.getElementById("offerId1").innerHTML = ResponseKbJSON;
  63.                                  break
  64.                            default:
  65.                                  document.getElementById("offerId1").innerHTML = ResponseKbJSON;
  66.                                  responseSpanKb.innerHTML = "HTTP Code:" + xmlHttp.status + " 恭喜:提交成功";
  67.                         }
  68.                 }else{
  69.                         responseSpanKb.innerHTML = "HTTP Code:" + xmlHttp.status + "被请求页面异常(程序出错或局域网问题)";
  70.                 }
  71.         }
  72. }

  73. function formSubmit()
  74. {
  75.     document.forms.FON.onsubmit();
  76. }

  77. //-->
  78. </script>
  79. <body onload="formSubmit()">

  80. <form name="FON" action="" style="display:none;" method="post" target="post_frame" enctype="multipart/form-data" onsubmit="KbRequestQueryPOST()">
  81. <iframe name='post_frame' id="post_frame" style="display:none;" mce_style="display:none;"></iframe>
  82.     <input type="text" name="phone" maxlength="120" value="1234567890"/><br />
  83.     <input type="text" name="macaddress" maxlength="120" value="11-22-33-44-55-66" /><br />
  84.     <input type="text" name="additional_1" maxlength="120" value="7ef44706c65938ceb87c814e844679dc5edf1c9c30de4b6d5af4504b4e6a7a8d" /><br />
  85.     <input type="text" name="additional_2" maxlength="120" value="V2" /><br />
  86.     <input type="text" name="additional_3" maxlength="120" value="RES" /><br />
  87.     <input type="text" name="validate" value="2012-05-20" />
  88.     <input type='submit' value='Enviar' >
  89. </form>


  90. <br><br><br><br>
  91. <font id='offerId1' name="offerId1" ></font>
  92. <br><br><br><br>
  93. <font id='serverResponseKb'></font>

  94. </body>
  95. </html>


阅读(2687) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~