File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in 'async' funtionality of ajax

 
Joshua Antony
Ranch Hand
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to build a sample web application using Ajax.

Currently I have 3 components in the web server:
1. a html file (A.html)
2. a java script (A.js)
3. a JSP (A.js)

I also have MYSQL as my backend.

The entries in the DB will be modified through some other web application.

The goal of the application is that once A.html is requested, it shall request
A.jsp using Ajax (XMLHttpRequest) and then draw the response into a graph.

Part of A.html has code like:



displayInBarGraph function is present in A.js and looks like below:



showBarGraph method is also present in A.js and is as below:



The problem that I am facing is that I get alert number 2 before alert number 1, why is it so?

I need to set the hidden input type value of A.html from the location in which alert number 1 is called and use that value from the location in which alert number 2 is called.

Regards,
Joshua
 
Joshua Antony
Ranch Hand
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that's because of ajax's async functionality, but how do I get my desired result ?

Regards,
Joshua
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because Asynch means it goes off and does things and does not wait. That is how it works.

It calls the function and keeps on chugging away. If the other one is supposed to hapen after the request, than you need to call it from your onreadystatechange functionality. When you do that, you can not use document.write.


Eric
[ December 07, 2007: Message edited by: Eric Pascarello ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64204
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd be far better off adopting jQuery or Prototype to help you with your Ajax. Either makes what you are trying to do brain-dead simple.

At this point in time, writing "raw" Ajax makes little sense.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64204
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, in jQuery you code would be:



It doesn't get any simpler than that.
 
Joshua Antony
Ranch Hand
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for your inputs.

Regards,
Joshua
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic