发布jQuery的.serializeArray();通过AJAX输出 [英] posting jquery .serializeArray(); output through ajax
问题描述
快速的问题
如果我已经使用jQuery的 .serializeArray()序列化形式;
功能,我需要对它做任何事情之前,我可以使用jQuery的AJAX把它关闭数据:
?
If I have serialized a form using jquery's .serializeArray();
function do I need to do anything to it before I can send it off using jquery's ajax data:
?
例如。我可以送过
[{名称:INP1,值:VAL1},{名称:INP2,价值:将val2'}]
原样,或者我需要preprocess它在某种程度上?
[{name: inp1, value: 'val1'}, {name: inp2, value: 'val2'}]
as is, or do I need to preprocess it somehow?
和,在PHP会怎么看呢?
and, in php how would I read this?
推荐答案
这将是更好地在这里使用 连载
。该功能可将您的表单的值到,可以用来作为AJAX调用的数据的简单串
属性:
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您使用 GET
方法发送该到PHP,您可以使用访问这些值 $ _ GET ['INP1']
和 $ _ GET ['INP2']
Presuming you send this to PHP using the GET
method, you can access these values using $_GET['inp1']
and $_GET['inp2']
编辑:您可以使用的 serializeArray 做了数组的参数字符串=http://api.jquery.com/jQuery.param > $。参数
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"
});
这篇关于发布jQuery的.serializeArray();通过AJAX输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!