Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to parse with Jquery.parseJson... part II
    text
    copied!<p>I have recently post here about the Jquery.parseJson. Now I'm in part II of my achievement. I got this script working with a stackoverflow user help.</p> <pre><code>&lt;input type="text" id="query" /&gt;&lt;button&gt;search&lt;/button&gt;&lt;br /&gt; &lt;div id="results"&gt; &lt;/div&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $('button').click(function(){ $("#query").val(); // Do nothing with this value var json = eval('({"name":"John"})'); $("#results").append('&lt;p&gt;' + json.name + '&lt;/p&gt;'); // $.getJSON('{"name":"John"}',function(json){ // $.each(json.results,function(i,obj){ // $("#results").append('&lt;p&gt;' + obj.name + '&lt;/p&gt;'); // }); // }); }); }); </code></pre> <p>Now that I have this code working I have build a real JSON to parse, here it is:</p> <pre><code>["http:\/\/guimaraes-braga.olx.pt\/seat-leon-1-9tdi-sport-111cv-iid-148286318", {"1":"http:\/\/static04.olx-st.com\/images\/v4\/logos\/logo-default.png"}, {"2":"http:\/\/images03.olx.pt\/ui\/10\/71\/18\/t_1292857323_148286318_1.jpg"}, {"3":"http:\/\/images04.olx.pt\/ui\/10\/71\/18\/t_1292886514_148286318_2.jpg"}, {"4":"http:\/\/images04.olx.pt\/ui\/10\/71\/18\/t_1292886514_148286318_3.jpg"}, {"5":"http:\/\/images02.olx.pt\/ui\/10\/71\/18\/t_1292886514_148286318_4.jpg"}, {"6":"http:\/\/images02.olx.pt\/ui\/10\/71\/18\/t_1292886514_148286318_5.jpg"}, {"7":"http:\/\/images02.olx.pt\/ui\/10\/71\/18\/t_1292886514_148286318_6.jpg"}, {"8":"http:\/\/images03.olx.pt\/ui\/10\/71\/18\/t_1292857323_148286318_1.jpg"}, {"9":"http:\/\/images04.olx.pt\/ui\/10\/71\/18\/t_1292886514_148286318_2.jpg"}, {"10":"http:\/\/images04.olx.pt\/ui\/10\/71\/18\/t_1292886514_148286318_3.jpg"}, {"11":"http:\/\/images02.olx.pt\/ui\/10\/71\/18\/t_1292886514_148286318_4.jpg"}, {"12":"http:\/\/images02.olx.pt\/ui\/10\/71\/18\/t_1292886514_148286318_5.jpg"}, {"13":"http:\/\/images02.olx.pt\/ui\/10\/71\/18\/t_1292886514_148286318_6.jpg"}, {"14":"http:\/\/images01.olx.com\/images\/spinner.gif"}, {"15":"http:\/\/images01.olx.pt\/ui\/10\/71\/18\/1292886514_148286318_1-Fotos-de--SEAT-LEON-19TDI-SPORT-111CV.jpg"}, {"16":""}] </code></pre> <p>This JSON above contain the URLs for images, and I have tried to pass this JSON just like in the first script, but it is not working... some more details in the code bellow.</p> <pre><code>&lt;?php $json = new img_json_output(); ?&gt; &lt;?php $data = $json-&gt;get_img_tags_as_json($json-&gt;get_page('http://guimaraes-braga.olx.pt/seat-leon-1-9tdi-sport-111cv-iid-148286318')); ?&gt; &lt;input type="text" id="query" /&gt;&lt;button&gt;search&lt;/button&gt;&lt;br /&gt; &lt;div id="results"&gt; &lt;/div&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $('button').click(function(){ $("#query").val(); // Do nothing with this value var json = eval(&lt;?php echo $data; ?&gt;); $("#results").append('&lt;p&gt;' + json.1 + '&lt;/p&gt;'); }); }); </code></pre> <p></p> <p>The PHP variable $data returns the JSON.</p> <p>Any clues on how to get this to work? Is the problem on my JSON format? Sorry for the extend of this question.</p> <p>Best Regards,</p>
 

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