簡體   English   中英

jQuery Post Ajax

[英]Jquery Post Ajax

我是jquery新手! 我正在使用下面的代碼插入記錄,將數據發布到目標asp頁面,但是什么也沒有發生,但是當我嘗試使用簡單的表單並以相同的編碼發布時,插入的數據!

jQuery代碼

<script>

    $(document).ready(function(){
// code here                               
   $("a").click(function(event){
 //    alert("Thanks for visiting!");
      $(this).addClass("test");
     event.preventDefault();
    $(this).hide("slow");

    $.post("suggested.asp", { profileid: "<%=(Recordset1.Fields.Item("MatchProfileID").Value)%>", seenby: "<%=(Recordset1.Fields.Item("Foruser").Value)%>" },


  function(data){
    alert("Data Loaded: " + data);
  });



   });

   //
 });


</script>

ASP代碼

<%
    ' Setting variables
    Dim rs, data_source

    data_source = "dsn=mydsn;"

    ' Creating Recordset Object and opening the database
    Set rs = Server.CreateObject("ADODB.Recordset")

    ' Lets open books table
    rs.Open "sugg", data_source

    rs.AddNew
    ' Now adding records
    rs("byid") = Request.Form("seenby")
    rs("vid") = Request.Form("profileid")
    rs.Update
Response.Write("Done")
    ' Done. Now Close the Connection
    rs.Close
    Set rs = Nothing
%>

好的,您的服務器端代碼可以正常工作。 可能在$ .post調用之前發生了錯誤?

在通話中添加一個參數-“文本”。 可能是數據格式錯誤

詳情請參閱這里: http : //docs.jquery.com/Ajax/jQuery.post#urldatacallbacktype

所有代碼接縫都可以。

檢查事項:

  1. 您是否要在與服務器代碼相同的域(即// localhost)中訪問客戶端代碼?
  2. 與客戶端代碼位於同一個文件夾中的suggested.asp文件嗎?

麻煩事

*使用以下簡單代碼來確保服務器端沒有問題:

<html>
<head>
</head>
<body>
   <%
   dim retval, x
   retval = ""
   For x = 1 To Request.Form.count()
      retval = retval + "p:" + Request.Form.key(x) + "=" + Request.Form.item(x) + ";"
   Next

   response.clear
   response.write "params: " + retval
   response.end
   %>
</body>
</html>

*使用Firebug檢查請求是否正在發送以及響應是什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM