2012-03-02 102 views
2

我試圖使用jQuery AJAX來獲取貼文本框的值:阿賈克斯後獲得價值

這是我的代碼:

$(document).ready(function(){ 
$('#submitButton').click(function() { 
    $.ajax({ 
      type: "POST", 
      url: "test.asp", 
      data: $("#form1").serialize(), 
      cache: false, 
      dataType: "html", 
      success: function(responseText){ 
       alert(responseText); 
      }, 
      error: function(resposeText){ 
       alert(resposeText); 
      }, 
     }); 

    return false; 
}); 
}); 

這是TEST.ASP頁:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> 
<% 
dim vwPW 

    vwPW = request.QueryString("vwPW") 

    response.write "returned " & vwPW 
%> 

我的形式是:

<form id="form1" method="post" action=""> 
      <table width="100" border="0" cellspacing="0" cellpadding="0"> 
       <tr> 
       <td><input name="vwPW" id="vwPW" type="password" class="textBox" maxlength="10" /></td> 
       <td><button class="GreyB" id="submitButton" name="submitButton"><span style="color:#000">Log in</span></button></td> 
       </tr> 
      </table> 
</form> 

我所得到的只是「重新調整」,之後沒有任何東西。我會做什麼不正確?

大衛

回答

5

你的AJAX使用POST,ASP將需要獲得使用request.form代替request.querystring價值 - 或者,改變你的Ajax來GET

+0

謝謝,我知道這是一件小事。 – StealthRT 2012-03-02 09:21:23

2

您的形式正在發佈,所以你無法通過Request.QueryString訪問您發送的變量,而是通過Request.Form。或者,將您的ajax電話更改爲type:'get'