ajax调用success,但没有返回数据

时间:2022-10-08 08:38:27

I am trying to parse a jQuery initialized array to PHP with an AJAX POST. However, I am trying to alert the ToString() of an array. Here is my ajax call, I am essentially trying to just take an array and pass it to my PHP for some further manipulation. Here is my code:

我正在尝试使用AJAX帖子将jQuery初始化数组解析为PHP。但是,我正在尝试通知数组的ToString()。这是我的ajax调用,我实际上是想获取一个数组并将它传递给PHP以进行进一步的操作。这是我的代码:

   AllArray.push("Alim");
   AllArray.push("Jonathon");
   AllArray.push("Kyle");
   var returnVal = AllArray.toString();
   $.ajax({        
   type: "POST",
   data: { 'allInfoArray' : returnVal },
   success: function() {
        console.log("AJAX Fired");  
   }

This is the PHP in my html file. I am trying to alert the array for debug purposes.

这是html文件中的PHP。为了调试的目的,我试图提醒这个数组。

 $allTeamArray = $_GET['allInfoArray'];
 echo "<script type='text/javascript'>alert('$allTeamArray');</script>";

1 个解决方案

#1


3  

Your ajax call passes the value via POST but you're alerting GET, which is why your alert isn't displaying the expected data.

ajax调用通过POST传递值,但您正在警告GET,这就是为什么您的警报没有显示预期的数据。

$allTeamArray = $_GET['allInfoArray'];
                ^ change to $_POST

#1


3  

Your ajax call passes the value via POST but you're alerting GET, which is why your alert isn't displaying the expected data.

ajax调用通过POST传递值,但您正在警告GET,这就是为什么您的警报没有显示预期的数据。

$allTeamArray = $_GET['allInfoArray'];
                ^ change to $_POST