[英]Receiving the serializeArray data from AJAX to processing php page
$('#submit').click(function()
{
var data = JSON.stringify($("#players_form").serializeArray());
alert(data);
$.ajax({ // Send the credential values to another checker.php using Ajax in POST menthod
type : 'POST',
data : data,
url : 'process.php',
success: function(responseText)
{
if(responseText == 1)
{
alert("Sucess");
}
}
In this code I have passed the form values to process.php but I could not be able to receive the posted values in process.php , could any one suggest me to recieve the array values in process.php 在这段代码中,我将表单值传递给了process.php,但是我无法在process.php中接收发布的值,有人可以建议我在process.php中接收数组值。
<form id="players_form" >
<input type=" text" name="main_name[]" value="">
<input type=" text" name="main_name[]" value="">
<input type=" text" name="main_name[]" value="">
<input type=" text" name="main_name[]" value="">
<input type=" text" name="main_name[]" value="">
<input type=" text" name="sub_name[]" value="">
<input type=" text" name="sub_name[]" value="">
<input type=" text" name="sub_name[]" value="">
<input type=" text" name="sub_name[]" value="">
<input type=" text" name="sub_name[]" value="">
<input type="button" value="Submit" id="submit">
</form>
you can use serializeArray method in two different way. 您可以通过两种不同的方式使用serializeArray方法。
var data = JSON.stringify($("form").serializeArray());
or 要么
var data = JSON.stringify($(":input").serializeArray());
Try this ajax script i make sure it works. 试试这个ajax脚本,我确保它可以工作。
$(document).ready(function() { $('#submit').click(function() { var post_data = $("#players_form").serializeArray(); $.ajax({ type: 'POST', data: post_data, url: 'process.php', success: function(responseText) { console.log(responseText); if (responseText == 1) { alert("Sucess"); } } }) }) });
On process.php get the value like this 在process.php上获得这样的值
$main_name = $_POST['main_name'];
$sub_name = $_POST['sub_name'];
$main_name_version = implode(',', $main_name);
$sub_name_version = implode(',', $sub_name);
echo $main_name_version;
echo $sub_name_version;
replace data by, 替换数据,
var data = $("#players_form").serializeArray();
make your request as, 提出您的要求,
dataType : 'JSON', data : {players:data},
and process data in server like below, 并在如下所示的服务器中处理数据,
$player = $_POST['players'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.