Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6083777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:26:33+00:00 2026-05-23T11:26:33+00:00

I am using JavaScript with jQuery AJAX and I have script as below; $(document).ready(

  • 0

I am using JavaScript with jQuery AJAX and I have script as below;

$(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&data2=2&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 !<br>Error !");
      }
    },
  });
});
});

This sends some data to my ajax file and changes background image of my div having id preview. 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 json_encoded array with result1 = true and result2 = imagename. The imagename variable contains full path to the image, images/img1.jpg. But the preview is a headache. Suppose, if it send request with data1=flename1, it will create a thumbnail img1.jpg 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.

How can I solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:26:34+00:00Added an answer on May 23, 2026 at 11:26 am

    Sounds like you have a caching problem. The first image is fetched from the server but when the images without the path changing, the browser will pull the image out of its cache and you’ll see the old one even though the server has the new one.

    The simplest and most reliable way I’ve found for cache-busting is to append a random number in a CGI parameter to the image’s URL:

    $('#preview').css({
        'background-image': 'url(' + result2 + '?cb=' + Math.random() + ')'
    });
    

    You might need to adjust your server configuration to ignore the ?cb but it should do that on its own.

    You could also try playing with the Cache-Control HTTP header on your server for the images in question. Setting:

    Cache-Control: no-cache
    

    should do it but the cache-busting URL kludge is more fool proof. Including the Cache-Control header for temporary images is still a good idea though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this jQuery-AJAX code below and a form: <script type=text/javascript> $(document).ready(function () {
I have index.php like this: <script type=text/javascript src=jquery-1.4.2.js></script> <script type=text/javascript src=ajax.js></script> <a href='one.php' class='ajax'>One</a>
I am working on a comment script using ajax, json and jquery. I have
Using jQuery autocomplete.. Want to replace hello in script below with javascript to identify
I've rewritten my family web site using JavaScript (JQuery) making Ajax calls to PHP
I am using JavaScript and jQuery. My main file has My.js and Ajax. My.js
I am using jQuery, JavaScript and PHP. My Ajax.php file just displays the data.
How to generate page numbers like the below using javascript/jquery? If the 5 th
I have an javascript that I place into a page using the code below.
How can i implement the below code with jQuery/AJAX timer,(I have created 2 URL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.