Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Send out a JSON response, like this from PHP:</p> <pre><code>&lt;?php echo json_encode($yourarray); ?&gt; </code></pre> <p>Then to adapt your AJAX function, do this:</p> <pre><code> $('#file').live('change',function(){ $('#preview').html(''); $('#preview').html('&lt;img src="loader.gif" /&gt;'); $('#data').ajaxForm(function(data){ var jsonData = jQuery.parseJSON(data); //acess it like alert(jsonData.toshow); //alert for your testing $(jsonData.toshow).insertBefore('.pic_content').hide().fadeIn(1000); }).submit(); }); </code></pre> <ul> <li>EDIT * Changes, update according the plug-in docs.</li> </ul> <p>Having never used the .ajaxForm jQuery plug-in, I went after the documentation, I'm going to put the code here, as clear as possible from what I read, I'm even letting the plug-in parse the response automatically into json.</p> <p>I didn't see any .ajaxForm().submit(), and there's no need to it according to the docs.</p> <pre><code>$('#file').live('change',function(){ $('#preview').html(''); $('#preview').html('&lt;img src="loader.gif" /&gt;'); $('#data').ajaxForm({ dataType: 'json', success: function(data){ alert("json string response from php: "+ data.toshow); $(data.toshow).insertBefore('.pic_content').hide().fadeIn(1000); } }); }); </code></pre> <p>dataType makes the plugin parse the response to json alone. and the success: function(data) happens if there was a response from PHP only. Implement it carefully, and give link if you still didn't get it right.</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