Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I have a file test.php with your content like</p> <pre><code> &lt;?php $data = array('items'=&gt;array('serverip'=&gt;'localhost', 'game'=&gt;'cs','protocol'=&gt;'48')); echo $data; ?&gt; </code></pre> <p>then</p> <pre><code>$ php -f test.php </code></pre> <p>produces the output:</p> <pre><code>Array </code></pre> <p>I think instead you want to deliver JSON encoded data.</p> <pre><code>&lt;?php $data = array('items'=&gt;array('serverip'=&gt;'localhost', 'game'=&gt;'cs','protocol'=&gt;'48')); echo json_encode($data); ?&gt; </code></pre> <p>The use of json_encode delivers the output:</p> <pre><code>{"items":{"serverip":"localhost","game":"cs","protocol":"48"}} </code></pre> <hr> <p>Your javascript tries to pass an object to jQueries .html function, when you need to make a string out of it first. An easy way to achive this is by using code like</p> <pre><code>&lt;script type='text/javascript'&gt; $(document).ready(function(){ var pprint = function (data){ var print = "{"; $.each(data, function(key, element){ if($.isPlainObject(element)) element = pprint(element); print = print + '&lt;br/&gt;' + key + ': ' + element; }); return print + "}"; }; console.log("test"); $.getJSON("test.php",{}, function(data){ console.log(data); $("#foo").html(pprint(data)); console.log("done."); }); }); &lt;/script&gt; </code></pre> <p>where the pprint function does some simple conversion of plain objects to strings. I got the idea to use $.each from <a href="https://stackoverflow.com/questions/4079274/how-to-get-an-objects-properties-in-javascript-jquery">this Answer</a>, but there are also more advanced approaches like <a href="https://j11y.io/javascript/prettyprint-for-javascript/" rel="nofollow noreferrer">https://j11y.io/javascript/prettyprint-for-javascript/</a>.</p> <hr> <p>To check on problems of $.getJSON you can use $.ajax:</p> <pre><code>$.ajax({ url: "test.php", dataType: 'json', data: {}, success: function(data){ console.log(data); $("#foo").html(pprint(data)); console.log("done."); }), error: function(jqXHR, textStatus, errorThrown){ console.log(textStatus); console.log(errorThrown); } }); </code></pre> <p>which you can find documented at <a href="https://api.jquery.com/jQuery.ajax/" rel="nofollow noreferrer">https://api.jquery.com/jQuery.ajax/</a>. Hopefully this can tell more about the problems you're experiencing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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