-1

Possible Duplicate:
Prevent caching of AJAX call

How do I get a new ajax request every single time my "a#changepw" is clicked. It just keeps retrieving the first ajax request and no more ajax requests are being made. I want it to get a new one every time I click the button.

       $(document).ready(function(){


    $('a#changepw').click(function(){
            //$('div#profilePassword').removeClass('hover');
            $('div#profilePassword').addClass('sloading');
            $('a#changepw').addClass('invisible');
            //alert('Hello World');

            $.get("changepassword", {

                }, function(response) {


                     //$('div.pw').html(response);

                    $('div#profilePassword').append($(response).fadeIn('slow'));
                    $('div#profilePassword').removeClass('sloading');
                    $('div#profilePw').removeClass('Select');
                    $('div#profilePassword').addClass('standard');

                });
Community
  • 1
  • 1
mnouh1
  • 234
  • 2
  • 9

2 Answers2

0

What I like to do is that anytime I am working with AJAX, attach a random string to the URL that you are fetching.

var url = 'somelocation.ext?rand='+new Date().getTime()
$.get(url, function(result){ ... });
RobB
  • 8,408
  • 1
  • 23
  • 34
0

The officially supported way to do this using jQuery's ajax calls us to pass the cache parameter as false:

$.ajax({
  url: "test.html",
  cache: false,
  success: function(html){
    alert(html);
  }
});

See cache: http://api.jquery.com/jQuery.ajax/

Caleb Gray
  • 2,930
  • 2
  • 19
  • 31