ajax post提交資料, input type=submit 返回prompt aborted by user

來源:互聯網
上載者:User

 

ajax post 提交 時 正常返回但是報:

 

[16:33:22.879] uncaught exception: [Exception... "prompt aborted by user"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: resource:///components/nsPrompter.js :: openTabPrompt :: line 462"  data: no] 

這個錯誤,用firebug  查看的時候顯示如上錯誤資訊,

 

該問題 主要為 用post提交表單的時候  和 用type=submit 提交表單的時候, 假如你想在 回呼函數內部做一些事情的時候 尤其是你想往頁面上輸出一些 html div的時候,情況是不一樣的

 

type=sumbit

 

是一次正常的提交,從發起請求到 response 回到頁面上 也就是回到表單處 為一次完整的請求,就是說 請求必須response回到發起提交form的頁面上,才算一次完整的請求

 

type=post

 

jquery post 請求的時候 請求的 完整 路徑及應答也和上面一樣,但是此刻我們想在回呼函數內部做一些事情,所以也就不能讓response的終點為頁面上了(發起form的頁面)而是應該在 jquery ajax 請求完成了之後用(return false語句) 將其攔截住 

 

代碼:

<script  type="text/javascript">
   var xmlHttp=null;

//建立XMLHttpRequest;
  function init(){
   
    if(window.XMLHttpRequest) { //Mozilla 瀏覽器
       xmlHttp = new XMLHttpRequest();
       alert("xmlhttpRequest")
     }
      else if (window.ActiveXObject) { // IE瀏覽器
        try {
          xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
          alert("Msxml2.XMLHTTP")
        } catch (e) {
          try {
             xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
             alert("Microsoft.XMLHTTP")
          } catch (e) {alert("瀏覽豈不支援")}
         }
     }

  }
  //回呼函數
  function callback(){
   
   if(xmlHttp.readyState==4){
   
    if(xmlHttp.status==200 ){
    
     alert(xmlHttp.readyState);
     alert(xmlHttp.responseText);
    }
    
   }
   
  }
  function processUser(){
   alert("processUser");
   var inputOneObj=document.getElementById('input_user');
   var inputTwoObj=document.getElementById('input_cadno');
   var inputThrObj=document.getElementById('input_pas');
   var name=inputOneObj.value;
   var id=inputTwoObj.value;
   var pasd=inputThrObj.value;
   //alert(opername);
   init();
   xmlHttp.onreadystatechange=callback;
   var post="username="+name+"&cardno="+id+"&password="+pasd;

 //servlet接受中文為亂碼的解決方案,一定要編碼(兩次)。
   post=encodeURI(post);
   post=encodeURI(post);
   var url="GuashiSevlet";
   //post方式發送請求到url地址,true表示非同步方式,false是同步方式

   xmlHttp.open("POST",url, true);
   xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   xmlHttp.send(post);
   
  }
   function checkuser(){
    var input_obj1=document.getElementById('input_user');
    var input_obj2=document.getElementById('input_cadno');
    var input_obj3=document.getElementById('input_pas');
    var user_name=input_obj1.value;
    var user_cadno=input_obj2.value;
    var user_pas=input_obj3.value;
    if(user_name == ""){
     alert("使用者名稱不可為空!");
     return false;
    }
    if(user_cadno == ""){
     alert("卡號不可為空!");
     return false;
    }
    
    if(user_pas == ""){
     alert("密碼不可為空!");
     return false;
    }
    else{
     processUser();

//千萬不能少了,否則會報prompt aborted by user異常
     return false;
    }
   
   }
</script> 

       

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.