开发者

How would I send a POST Request via Ajax?

I have a php page, Post.php it recieves the POST's Action, and that has two functions. Insert, and Update.Now how would I go about posting INSERT with this Ajax code. The code posts update fine but is doesnt post insert at all.

 $(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()开发者_StackOverflow){            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. List item


Your second call to $.ajax uses type: "GET" whereas the first uses type: "POST". Try switching the second one to "POST".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜