2012-03-02 108 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'