posting jquery .serializeArray(); output through ajax

六月ゝ 毕业季﹏ 提交于 2019-11-29 00:20:56

It would be better here to use serialize. This converts your form's values into a simple string that can be used as the AJAX call's data attribute:

var myData = $('#yourForm').serialize();
// "inp1=val1&inp2=val2"
$.ajax({
    url: "http://example.com",
    data: myData
});

Presuming you send this to PHP using the GET method, you can access these values using $_GET['inp1'] and $_GET['inp2']


Edit: You can convert an array made by serializeArray into a parameter string using $.param

var myData = $('#yourForm').serializeArray();
// remove items from myData
$.ajax({
    url: "http://example.com",
    data: $.param(myData) // "inp1=val1&inp2=val2"
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!