Welcome Guest, Not a member yet? Register   Sign In
JQuery & AJAX & IE Div Caching...
#1

[eluser]internut[/eluser]
Hey all,

If anyone can look this over and point me in the right direction... What I have works great in Firefox. Div loads new data no problem after the controller is called which calls the model and adds a record to the DB. IE it adds a record to the database as well but the DIV is not refreshing like FireFox does and showing the new data.

I've researched high and low, tried many things but to no avail. Should I be doing something other then .load ? Seems like a cache issue which I see a lot of google posts about but what I've tried is not fixing it on the explorer side.

In my view file:

Code:
[removed]
$(function(){

  $('#submit').click(function(){

    $.ajax({
      type: 'POST',
      url: 'index.php?/messages/add',
      dataType: 'html',
      data: { message: $('#message').val(), age: $('#age').val() },
      success: function(data){
        $("#content").load("index.php?/messages/view/");
      },
      error: function(){
        alert("An error has occurred. Please try again.");
      }
    });
    return false;
  });

   $("#content").load("index.php?/messages/view/");

});
[removed]

I'm new to this area and would like to think I'm making quick progress but need some assistance. Appreciate your time.
#2

[eluser]depthcharge[/eluser]
Hi,

if it's a cache issue, As in the browser is caching the return from the ajax load, what happens if you make the call a dynamic generated url, i.e using a dummy method parameter used for the only purpose of making the call unique maybe using a parameter generated from the current date/time / timestamp / hash etc?

##DATETIME## below being replaced with a variable containing the current unique string of sorts. Obviously if you are using other parameters your case might change.

Code:
$("#content").load("index.php?/messages/view/##DATETIME##");

This is just a brainfart!, just a thought.
#3

[eluser]internut[/eluser]
Those are the suggestions all around google that I have seen. Maybe I'm not going about it the right way but I did throw a php rand() on the end of the URL to see if that would work... Though on the page load its simply that. So I guess I would need some javascript code to get a random # or that datetime.

That makes more sense. I'm not up on the code I need to use to get that. I'll hunt that down now. Any tips appreciated.

On that note... Anyone recommend Ajaxify?

Can it work with CI URLs?
#4

[eluser]internut[/eluser]
Think I just got it with:

Code:
[removed]
$(function(){

  $('#submit').click(function(){

    $.ajax({
      cache: false,
      type: 'POST',
      url: 'index.php?/messages/add',
      dataType: 'html',
      data: { message: $('#message').val(), age: $('#age').val() },
      success: function(data){
        $("#content").load("index.php?/messages/view/"+ new Date().getTime());
      },
      error: function(){
        alert("An error has occurred. Please try again.");
      }
    });
    return false;
  });

   $("#content").load("index.php?/messages/view/");

});
[removed]
#5

[eluser]depthcharge[/eluser]
hmm, maybe forcing no-cache with the use of headers from the method in your controller would work?

It would save you the trouble of doing it with javascript, Would be interested if this is possible anyone??
#6

[eluser]internut[/eluser]
I've read that is the way to go as well but I have not found a way. I've tried a few things but have not got anywhere with no cache tries.
#7

[eluser]depthcharge[/eluser]
What headers have you tried?

A doc that might give you some ideas Here




Theme © iAndrew 2016 - Forum software by © MyBB