jquery serialize and $.post

前端 未结 7 916
独厮守ぢ
独厮守ぢ 2020-12-01 12:32

I\'m trying to send a lot of data from a form using the $.post method in jQuery. I\'ve used the serialize() function first to make all the form data into one long string whi

7条回答
  •  囚心锁ツ
    2020-12-01 12:52

    One more possible reason for this issue: If you have a form without any sort of submission action assigned to it, whenever you press the "ENTER" key while filling out the form, the form will be submitted to the current URL, so you will see the serialized data appear in the URL as if you were using a GET ajax transaction. A simple solution to this problem, just prevent ENTER from submitting the form when its pressed:

    //Prevent Form Submission when Pressing Enter
    $("form").bind("keypress", function(e) {
    if (e.keyCode == 13)
        return false;
    });
    

提交回复
热议问题