How do I pass a JSON array into the URL?

arrays, jquery, json, php

Solution

Try JSON.stringify

$.get('/json.php?arr='+JSON.stringify(arr),function(result)

Problem

JavaScript/JQuery ``` var arr=[]; $('.element').each(function(i) { arr.push({"id":i,"value":$(this).attr('data-value')}); }); $.get('/json.php?arr='+arr,function(result) { alert(result); }); ``` PHP ``` <?php $j = json_decode($_GET['arr'], true); foreach($j as $k => $v) { echo $v['id'].':'.$v['value'].'<br />'; } ?> ``` Problem But the problem is that the URL looks like `/json.php?arr=[object Object],[object Object]` instead of `/json.php?arr=[{"id":1,"value":"value 1"},{"id":2,"value":"value 2"}]`. Do I need to convert the object to a string? But I don't want to use another library other than JQuery. Is this possible? :/

Original source