我有两个不同的数组,即 main_name[] 和 sub_name[]。 我必须使用 AJAX 将这些值传递到下一页,以便插入到 DB 中。你能帮帮我吗,我如何将数组作为 AJAX 中的数据传递。 HTML
<input type="text" name = "main_name[]" value = "" >
<input type="text" name = "sub_name[]" value = "" >
JS
$.ajax({
type: "POST",
dataType: "json",
url: "response.php", //Relative or absolute path to response.php file
data: data,
success: function(data) {
$(".the-return").html
);
alert("Form submitted successfully.\nReturned json: " + data["json"]);
}
});
return false;
});
});
最佳答案
$('form').serialize()
将连同值一起序列化您的所有表单元素,并与 ajax 查询一起发送。
$.ajax({
type: "POST",
dataType: "json",
url: "response.php", //Relative or absolute path to response.php file
data: $('#form_id').serialize(),
success: function(data) {
$(".the-return").html
);
alert("Form submitted successfully.\nReturned json: " + data["json"]);
}
});
return false;
});
});
关于javascript - 将文本框数组传递给 ajax json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33228236/