我如何通过Ajax发送POST请求?

时间:2010-12-25 04:48:04

标签: html ajax

我有一个php页面,Post.php它接收了POST的Action,它有两个功能。 Insert和Update.Now我将如何使用此Ajax代码发布INSERT。代码帖子更新很好,但根本没有插入。

 $(document).ready(function(){
    //global vars   var inputUser =
 $("#nick");    var inputMessage =
 $("#message");     var loading =
 $("#loading");     var messageList =
 $(".content > ul");        //functions
 function updateShoutbox(){         //just
 for the fade effect
 messageList.hide();
 loading.fadeIn();      //send the post to shoutbox.php         
  $.ajax({ type:
 "POST", url: "Shoutbox.php", data:
 "action=update",complete:
 function(data){
 loading.fadeOut();
 messageList.html(data.responseText);
 messageList.fadeIn(2000); } }); }
 function checkForm(){
 if(inputUser.attr("value") &&
 inputMessage.attr("value"))return
 true;      else            return false;   }   
    //Load for the first time the
 shoutbox data  updateShoutbox();   
    //on submit event
    $("#form").submit(function(){
        if(checkForm()){            var nick =
 inputUser.attr("value");           var
 message = inputMessage.attr("value");
            //we deactivate submit button while
 sending            $("#send").attr({
 disabled:true, value:"Sending..." });
            $("#send").blur();          //send the
 post to shoutbox.php           $.ajax({
                type: "POST", url: "Shoutbox.php", data: "action=insert&nick=" + nick +
 "&message=" + message,
                complete: function(data){
                    messageList.html(data.responseText);
                    updateShoutbox();
                    //reactivate the send button
                    $("#send").attr({ disabled:false, value:"Shout it!" });
                }
             });        }       else alert("Please fill all fields!");      //we prevent the
 refresh of the page after submitting
 the form       return false;   }); });*emphasized text*
  1. 列表项

1 个答案:

答案 0 :(得分:1)

您对$.ajax的第二次通话使用type: "GET",而第一次使用type: "POST"。尝试将第二个切换为"POST"