• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inconsistent ajax calls to servlet functions

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I realise that ajax is asynchronous but I hope this is not the reason for my issue.

I am using the MVC model. I have an order page. Top right has tally section (no of lines, no of pieces & subtotal). I use ajax to update this - works without issue.

When an user changes a quantity the following event fires two javascript functions - updOrder() & updExtend():



updOrder() updates the tally section. updExtend() updates the extended price.

When it it working the console shows:



So addOrdItem is called from updOrder() which makes the item quantity & price changes and responds with an xml style respone to update the tally section. As I said - no issue.

Then ordItemExtend is called from updExtend(). (I list the contents of the array to make sure everything matches) ordItemExtend returns the extended price and I update the extended field using the DOM model. I get no error messages at the server or browser level (use Firefox error console) when it works or does not work completely.

When it doesn't work - this is what I get:



The last two lines should be right after "addOrdItem orditem is: 550586 1
" but are not and so the first line of the ordItemExtend check has the wrong quantity and extended price.

I suspected the browser cache so tried the ServletFAQ no-cache solution and sticking a random number on the end of the URL. The response.setHeader no-cache etc did not work (or I could not get it to fix the problem). The random number worked but refreshes the whole page and I lose my tab order.

Puzzled why the updOrder() tally total works consistently and the updExtend() does not. I have tried separating them - putting updOrder() onchange and updExtend() onblur with no success.

Please advise. Thanks.
 
Peter Brown
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Update - Firefox is affected by it. Internet Explorer is updating extended pricing without issue... I will see what I can find to fix this and close the thread - unless someone beats me to it.

Thanks.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pedro Bruno:
Hello,

I realise that ajax is asynchronous but I hope this is not the reason for my issue.



It very well might be the reason. Without actually seeing the code you write to make the ajax calls it is hard to say. I suspect that it is because you are issues the calls back to back. The problem with that is the second ajax call might actually complete before the first one, depending on a whole lot of factors like network latency, database latency, whatever. If you need to ensure that one call happens before/after another call then you need to code it that way.

I don't know if you are using a javascript library or doing the ajax the old school way but you should have some sort of callback method for when the ajax calls complete. Your updExtend() call should be placed in this on complete callback function for updUpdate(). That way you know for sure the updUpdate() is going to be called and complete before the updExtend() call ever fires.
 
Peter Brown
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Gregg.

I will try that as I would like to see it work in Firefox so I can offer both options to end users.
 
Peter Brown
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I remember why I didn't try this - got confused...

My updOrder code is



The validateCallback is



If I understand correctly I should be putting the updExtend() inside the "msg == updated" statement. My question is what is the format for passing parameters into validateCallback?

updExtend() has three fields it requires.

Do I do something like this in the updOrder() function?


and if so does my validateCallback look like this:



Which does not seem to make sense to me...

Thanks,
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need a closure

var ajax = new AJAXInteraction(url, function(response){ validateCallback( response, field1, field2, field3); });

Eric
 
Peter Brown
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the correction Eric.
 
reply
    Bookmark Topic Watch Topic
  • New Topic