0

I have a problem.

I am using zend to create a web application and I have come across a problem with my jquery and javascripts.

I have a page showing a order with jquery code written on the page within script tags.

I'm using jquery $.post to load each page on the website.

My problem is that when you select a fresh order page (first time accessing a order page), then click on a button that opens a jquery dialog box to add information to the order the correct post variables are sent; but if you then went on to another order and clicked that add button again it sends the post variables from the previous order.

I assume the previous javascript information had been cached. If I empty my cache it works fine for the order again but fails on the order after it.

I am using php to stick the variable in question (order ID) into the inline javascript code.

I'm guessing this is my downfall.

What I don't understand is the javascript works fine for the initial loading of the page because it then goes and uses ajax to grab a few more sections of the page. That works fine but when I use my button it reverts back to the original order ID used at the beginning.

Attached is my code:

function getFreightTable()
    {
        $.post("order/freighttable", "OrderID=<?= $this->orderID; ?>" , function(data){
            $("#tabs-3").html(data);
        });
    }

    $("#OrderAddFreightButton").live('click',function() {
        $.post("freight/new", "OrderID=<?= $this->orderID; ?>", function(data) {
            $("#orderAddFreightDialog").html(data);
            $("#orderAddFreightDialog").dialog({    
                autoOpen: true, 
                hide: 'slide',
                show: 'slide', 
                title: 'Add New Freight Information',
                closeOnEscape: true,
                close: function(event, ui) 
                { 
                    $("#orderAddFreightDialog").empty();
                    getFreightTable();
                }
            });
        });
        return false;
    });

My php is placing the correct order id's within the code but the javascript is reverting to an older set.

I am having a similar issue with another section of the site and javascript reverting back to javascript code from 3 weeks ago even though I use it on a different computer and cleared the cache. This is freaking me out.

2
  • 3
    You may have a problem with your JS, but I doubt it's a JS caching problem. Go get Fiddler2 on your client machine. It can shed a lot of light on weird problems like this as you browse your site Commented Jan 20, 2011 at 3:25
  • The problem lies elsewhere. POST are not cached. Commented Jan 20, 2011 at 3:44

2 Answers 2

4

You can use jQuery's .ajax() to specify cache: false, which will force the request not to cache the request -- note that you have to rewrite your function to no longer use $.post and instead use $.ajax. If you don't want to do that, you can also add to your url in order to trick the browser:

$.post("url...?c=" + Math.random())

It isn't the best way to do things, but they both work.

Sign up to request clarification or add additional context in comments.

Comments

0

I have tried cache : false

I have tried adding the random get variable at the end.

I am aware that post is not cached but the javascript that is on each page must be because the javascript being used is the first version from the initial view of the page.

1 Comment

none of these work. i have been thinking it might have something to do with jqueries .live() function remaining in play.

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.