prototype
prototype

Reputation: 3313

AngularJS caches $http.post responce

I've been fiddling with AngularJS for a while now and I came across a problem.

Every time a make a change to an element (create/delete/update) the request is sent and saved to the database. The problem is that my changes are not loaded the next time I refresh the page - old data is sent as a response from the server without the changes I've made.

I'm using .NET MVC for the backend and AngularJS on the front-end.

Any help would be appreciated.

Thanks!


Edit:

I've a reason to believe that .net is the problem - After I rebuild the whole solution it loads the changes.

Upvotes: 0

Views: 143

Answers (4)

Jyoti Puri
Jyoti Puri

Reputation: 1346

Do you see something like this in browser, it means that browser is caching the response and the response you are getting is not coming from server.

enter image description here

This caching is not at level of javascript or rather angular but browser caching. There are various ways to make sure that browser does not servers response from cache.

Upvotes: 0

Jyoti Puri
Jyoti Puri

Reputation: 1346

Caching is at times at level of browser and you can not force browser to not cache from javascript. This is not specifically Angular issue.

If its caching of some html/js file what you can probably do is append timestamp to url so every time your url is new and no caching is done.

Upvotes: 0

Borys Generalov
Borys Generalov

Reputation: 2345

In fact, conceptually correct way is to disable caching on server side. The reason is that you have custom behavior and you want to load "fresh" data after every postback. Whenever you call the same method via another client or access the url directly, you should see up-to-date data. Here is the sample excerpt how to disable caching:

[OutputCache(Duration=0, VaryByParam="*")]
public JsonResult Details()
{
    //snip snip
    return Json(theResult, JsonRequestBehavior.AllowGet);
}

Upvotes: 1

CORSAIR
CORSAIR

Reputation: 531

Try something like this:

$http.post({
    url: "example.cpm",
    cache: false      //This comes from jQuery
    //etc..
})

Upvotes: 0

Related Questions