tags:

views:

46

answers:

2

Hi there people, I need help urgently please, my issue is this:

I have an MVC app that does a lot of work with jquery ajax (post), to retreive customer info and load it to the web page. The problem is, that on internet explorer 7, when I click twice a link that retreives the info via ajax ($.post or $.getJSON), the info doesn't refresh; it shows me the info of the first customer i clicked, not the second one, so the info is wrong. I tried to make a debug on the code, and on the second click it doesnt even enter to the action that retreives the data from the database.

I suspect that the problem is with the browser cache, but I don't know how to handle it.

I attach my code, its working fine, expect for the problem i mention previously:

$.getJSON(pathSite + 'PorServiceQuery/GetJsonInfo', {},
                function(resp) {
                    $('#txtPhone').attr('value', resp.ClpCustomerPhone);
                    $('#txtCelPhone').attr('value', resp.ClpCelPhone);
                    $('#txtEmail').attr('value', resp.ClpEmail);
                });

Thanks in advance.

A: 

I've seen this behavior if the user clicks twice before the initial response returns. Are you sure that's not what's happening (regardless of the browser)? You might want to try using Fiddler to confirm when the request is going out vs when it is returning vs when the user is clicking.

Another idea is that you can set IE cache settings to ALWAYS check for new versions of pages.

Michael Bray
Hi, thanks for your solution. Setting the IE cache works for my issue, but is there another way? cause I can't control my customer browser settings?? Thanks again.
lidermin
You could ensure that the URL request is different, although this may not be possible with the way the web service is set up, or may require using a GET instead of POST. I had to do this at one point, and basically I just add a random number (or a number based on timer) as a dummy parameter to the AJAX URL. This guarantees the URL is different and the browser shouldn't cache it. You might also want to check the service itself and see if you can set cache-control settings on the response.
Michael Bray
A: 

The solution was to use $.post instead of $.getJson, the reason is that the getjson does an http get and that's why I didn't saw my data refreshed.

lidermin