Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to make sure, that your return values are "really" json. Some browsers dont accept json which isn't syntactically correct.</p> <p>so make 100% sure you return something like:</p> <pre><code>{"foo": 1, "bar": "foobar"} </code></pre> <p>this is correct json.</p> <p>e.g. this is not:</p> <pre><code>{'foo': 1, 'bar': "foobar"} </code></pre> <p>this is also wrong:</p> <pre><code>{foo: 1, bar: "foobar"} </code></pre> <p>further some advices to your javascript code:</p> <pre><code> return { label: item.name, value: item.name } </code></pre> <p>this is not correct, wrap your keys in quotes. return { "label": item.name, "value": item.name }</p> <p>Generally I've read many time you should do ajax calls as GET Requests not POST, because POST produces more overhead and traffic. But don't nail me for that.</p> <p>Further, when you want to return e.g. an array from within php, use json_encode($var)</p> <p><a href="http://php.net/manual/de/function.json-encode.php" rel="nofollow">http://php.net/manual/de/function.json-encode.php</a></p> <p>For your concrete use case return:</p> <pre><code>{"name": "pizza", "point": 1} </code></pre> <p>from within your php script.</p> <p>Try this on your page in firebug:</p> <pre><code>var obj = jQuery.parseJSON('[{"name":"pizza","point":1}]'); for (var i = 0; i &lt; obj.length; i++) { var object = obj[i]; for (property in object) { var s = property + "=" + object[property] + "&lt;br&gt;"; $("#console").after(s); console.log(s) } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload