2

I believe my load method is sometimes caching and I want to disable this.

I'm currently using:

function getClient(date, appId) {

    $("#cPlaceholder").load("/GetClient?id=" + appId+",
                 function () {
                     $('#clientModal').modal('show');
                 });
    }

But I've read that I should use ajaxSetup so changed to..

function getClient(date, appId) {
 $.ajaxSetup ({
            url:"/GetClient?id=" + appId+",
            cache: false,
            success: function(result){
               ("#cPlaceholder").html(result);
                $('#cPlaceholder').modal('show');
            }
        });
}

But this does not seem to execute? Any ideas?

1
  • Any logs in console ? in XHR request you see them ? Commented Apr 26, 2017 at 11:44

1 Answer 1

1

Change it back to just ajax;

 $.ajax ({
            url:"/GetClient?id=" + appId,
            cache: false,
            success: function(result){
                $("#cPlaceholder").html(result);
                $('#cPlaceholder').modal('show');
            }
        });

Ajaxsetup does it globally so you could first run;

$.ajaxSetup({ cache: false });

Then your load() call. But Ajaxsetup does not replace the ajax call it just sets the defaults to be used in future ones.

P.S. You also have two typos;

url:"/GetClient?id=" + appId+",

should not have the last quote;

url:"/GetClient?id=" + appId,

and

("#cPlaceholder").html(result);

is missing the $

$("#cPlaceholder").html(result);
Sign up to request clarification or add additional context in comments.

3 Comments

Hey, should I put this just in the script section? ie <script> $.ajaxSetup({ cache: false });</script>
@D-W That is indeed where it would go, BEFORE the actual ajax call. However I highly recommend using the cache: false inside the individual ajax call instead, because if you later add another ajax call to the page and DO want it to use the cache, this will prevent that from happening. Best to be explicit...
@D-W Also check your typos

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.