1

basically I am trying to load some PHP into a DIV using JS. Using this code:

$('#preview').load("includes/event_image_crop.php?img=" + fname);

However, its not just putting the fname string in there its adding a random string too like this &_=1369168657782

Any ideas?

Thanks

Halcyon
  • 57,230
  • 10
  • 89
  • 128
Steve_M
  • 435
  • 1
  • 10
  • 21

1 Answers1

3

This is a feature designed to prevent caching. It should have no effect on the page (unless you need to use the _ GET variable), but if you need to disable it you should set cache: true using ajaxSetup:

$.ajaxSetup ({
    cache: true
});

Of course, as Ian mentions, this will affect every Ajax call on the page, so be aware of that if you have other Ajax calls. It might be better to refactor your code and use a more configurable function than .load().

See a similar (opposite) question here: Stop jQuery .load response from being cached

Community
  • 1
  • 1
nullability
  • 10,545
  • 3
  • 45
  • 63
  • I am using the ajaxForm plugin - and on success of this form submission is runs that code above. I've added the code you suggested and still no luck... – Steve_M May 21 '13 at 20:47
  • 1
    I would really **not** suggest using `$.ajaxSetup` for this. Any other AJAX requests on the page, in any variation, will have this applied to it. And anyways, you want **`cache: true`** if you don't want the `&_=124234` on the end – Ian May 21 '13 at 20:49
  • Yeah - Changed it to true in the ajaxForm itself. Thanks :D – Steve_M May 21 '13 at 20:49
  • @Ian You're right, `cache: true` is correct. Updated my answer. – nullability May 21 '13 at 21:03
  • 1
    I took back my downvote, but I still strongly agree with @Ian re `$.ajaxSetup`. Best not to muck with globals if you don't need to. – Evan Davis May 21 '13 at 21:09