title: Image display using jQuery AJAX
body: <p>I am using JavaScript with jQuery AJAX and I have script as below;</p>
  
  <pre><code>$(document).ready( function() {
  $('#process').click(function() {
    var $process = $(this);
    var $message = $process.parent().parent().next().children('td');
    $message.text("Processing...");
    $.ajax({
      type: 'POST',
      url: 'myajaxfile.php',
      data: 'data1=flename1&amp;data2=2&amp;data3=mix',
      dataType: 'json',
      cache: false,
      success: function(result) {
        var result1 = result[0];
        var result2 = result[1];
        if(result1 == "true"){
          alert("true");
          $('#preview').css({ 'background-image':'url(' + result2 + ')' });
          $message.text("");
          return(false);
        }else{
          alert("false");
          $message.html("Error !&lt;br&gt;Error !");
        }
      },
    });
  });
  });
  </code></pre>
  
  <p>This sends some data to  my ajax file and changes background image of my div having id <code>preview</code>. Everything works well. But still some confusing problem. The ajax file first make some thumbnail image according to data send where data1 = filename1, data1 = filename2 etc etc. If thumbnail is made, it will return a <code>json_encoded array</code> with <code>result1</code> = <code>true</code> and <code>result2</code> = <code>imagename</code>. The <code>imagename</code> variable contains full path to the image, <code>images/img1.jpg</code>. But the preview is a headache. Suppose, if it send request with <code>data1=flename1</code>, it will create a thumbnail <code>img1.jpg</code> and is correctly displayed. Then i changed data1 to data2, refreshed page and sent request. but the image displayed was the previous image. I checked directory and found each time for the request, a corresponding correct image file is created in directory. but the problem is with the display. Also, the correct image is getting displayed if I repeat Ajax request for 2 or more times after refreshing the page. it is because of the same image name. but I have no other choice. I am using Firefox.</p>
  
  <p>How can I solve this?</p>