javascript - jQuery $.getJSON : Passing arrays to PHP - Stack Overflow

I have javascript passing an array to PHP with:var mapIDArray = ["4f8d7684791635ec2e000000"

I have javascript passing an array to PHP with:

         var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];

         $.getJSON("rebound.php",
            { 
                'mapIDs[]' : mapIDArray
            },

            function(output){

                console.log(output);

            }
        );

In rebound.php, I try to read the passed array (var_dump, print_r, etc.), such as:

print_r($_GET['mapIDs[]']);

But no luck...

I have javascript passing an array to PHP with:

         var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];

         $.getJSON("rebound.php",
            { 
                'mapIDs[]' : mapIDArray
            },

            function(output){

                console.log(output);

            }
        );

In rebound.php, I try to read the passed array (var_dump, print_r, etc.), such as:

print_r($_GET['mapIDs[]']);

But no luck...

Share Improve this question asked Apr 17, 2012 at 20:51 alyxalyx 2,7436 gold badges45 silver badges69 bronze badges 1
  • try print_r($_GET['mapIDs']); – Roman Pominov Commented Apr 17, 2012 at 20:57
Add a ment  | 

2 Answers 2

Reset to default 5

You don't need add the [] to the name.

var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];
$.getJSON("rebound.php",
{ 
   mapIDs: mapIDArray
},
function(output){
    console.log(output);
});

Then in your PHP: $_GET['mapIDs'] will be an array.

It'd be print_r($_GET['mapIDs']); on the server-side, and

var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];
$.ajax("rebound.php",
            dataType: 'json',
            data:
            { 
                'mapIDs[]' : mapIDArray[0],
                'mapIds[]' : mapIdArray[1],
            },
            traditional: true,
            success: function(output){

                console.log(output);

            }
        );

on the client side. The key issues being that first, PHP sees it an an array with name 'mapIDs', even though it was mapIDs[] as a GET parameter, and second, multiple fields need multiple entries.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745654996a4638489.html

相关推荐

  • javascript - jQuery $.getJSON : Passing arrays to PHP - Stack Overflow

    I have javascript passing an array to PHP with:var mapIDArray = ["4f8d7684791635ec2e000000"

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信