如何从jquery ajax formData到php获取数组值

如何从jquery ajax formData到php获取数组值,php,jquery,ajax,Php,Jquery,Ajax,我正在尝试使用jquery Ajax formData将一个输入字段的值与其他一些输入字段一起传递到PHP中,除了我在成功传递数组值方面遇到问题之外,一切似乎都很好,我已经尝试了很多,但没有明显的成功 首先,我尝试了SerialiseArray()方法。下面是我的代码 <form> //other input field below... . . . //this is the code to include my array which is in _categor

我正在尝试使用jquery Ajax formData将一个输入字段的值与其他一些输入字段一起传递到PHP中,除了我在成功传递数组值方面遇到问题之外,一切似乎都很好,我已经尝试了很多,但没有明显的成功

首先,我尝试了SerialiseArray()方法。下面是我的代码

 <form>
 //other input field below...
  .
  .
  .
//this is the code to include my array which is in _categories-list.php
<div class="form-group">
<label for="artist">Select Categories </label>
<?php include('../_categories-list.php') ?>
</div>    </form>

  var Category = $('#categoriesList').serializeArray();
  $.each( Category,function(i,field){
  formData.append('categoriesList', field.value + "");
                               });
   $('.msg').text('Uploading in progress...');
         ajaxcall =       $.ajax({
                    url: 'page-videoFunc.php',
                    data: formData, 
                    processData: false,
                    contentType: false,
                    type: 'POST',});
我还尝试了另一种类似的方法

<form>
 //other input field below...
  .
  .
  .
//this is the code to include my array which is in _categories-list.php
<div class="form-group">
<label for="artist">Select Categories </label>
<?php include('../_categories-list.php') ?>
</div>  </form>

  var Category = $('#categoriesList').serializeArray();
  formData.append('categoriesList', Category);//note that code changes here from the above method used
   $('.msg').text('Uploading in progress...');
         ajaxcall =       $.ajax({
                    url: 'page-videoFunc.php',
                    data: formData, 
                    processData: false,
                    contentType: false,
                    type: 'POST',});
最后,我尝试了这个:serialize()

我不知道如何在这个方法中只从查询字符串中获取值,以便将其放入数据库

请帮助我为我正在使用的上述任何一种方法提供解决方案,我已经为此工作了将近42个小时,它减慢了我的项目的速度

var Category = $('#categoriesList').serialize();
$.ajax({
                    url: 'page-videoFunc.php',
                    type: 'post',
                    data:{
                         action:'update_data',
                         form_data:Category 
                     },

});
在page-videoFunc.php文件中,使用解析表单_数据

if($\u POST['action']=='update\u data'){
解析字符串($\u POST['form\u data'],$my\u form\u data);
回声“;
打印(我的表格数据);
}

在使用parse_str切断添加到序列化数据的URL后,要获取数组的所有值,您应该执行以下操作:


您好Shivendra Singh,谢谢您的回复,请问变量$my_form_数据来自哪里?您是否也在考虑在数据部分data:{action:'update_data',form_data:Category}我已经有了formdata,它是表单中所有字段的嵌入,而不仅仅是Category,或者我可以这样做:data:{操作:'update_data',form_data:Category,data:formData,}其中formData是var formData=new formData();还附加到formok中的其他字段:{操作:'update_data',form_data:Category}这是一个添加的例子。你可以使用formdata来代替类别。在我的表单数据中解析表单数据。我添加了parse_str check的链接。哇,谢谢你,它刚刚工作了,最后一个方法现在正在使用parse_str工作,虽然我以前使用过它,但没有很好地使用它,不得不阅读parse_str手册,再次感谢。我我在使用echo$output['arr'][0];echo$output['arr'][1];同时打印出所有值时遇到问题;这时我知道用户选择了多少值,但实际上在这个场景中我不知道,所以使用parse_str后如何打印出所有值。
//output
[object object] [object object]
<form>
 //other input field below...
  .
  .
  .

//this is the code to include my array which is in _categories-list.php
<div class="form-group">
<label for="artist">Select Categories </label>
<?php include('../_categories-list.php') ?>
</div>  </form>

  var Category = $('#categoriesList').serialize(); //Note i used just serialize() here
  formData.append('categoriesList', Category);
   $('.msg').text('Uploading in progress...');
         ajaxcall =       $.ajax({
                    url: 'page-videoFunc.php',
                    data: formData, 
                    processData: false,
                    contentType: false,
                    type: 'POST',});
 //output
 categoriesList%5B%5D=blues&categoriesList%5B%5D=hip-hop
var Category = $('#categoriesList').serialize();
$.ajax({
                    url: 'page-videoFunc.php',
                    type: 'post',
                    data:{
                         action:'update_data',
                         form_data:Category 
                     },

});
if($_POST['action'] =='update_data'){
parse_str($_POST['form_data'], $my_form_data);
echo "<pre>";
print_r($my_form_data);
}
 parse_str($_POST['name'], $output);
  $x = $output["name"];
  foreach ($x as $key => $value) {
   echo $value;
      }