LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-31-2009, 02:12 AM   #1
moistTowelette
Member
 
Registered: Sep 2003
Posts: 78

Rep: Reputation: 15
JavaScript - getting XMLHttpRequest to return asynchronously before pageload complete


Hi

AJAX n00b here with a JavaScript question.

I'm trying to write a JS applet that hits a URL on a server running Apache with mod_python. The idea of this applet is to retrieve incremental 'percentage complete' information about an operation running on the server.

I can get Apache/mod_python to return this information in real-time when the HTTP request is made, one update at a time, before returning. The problem is that XMLHttpRequest will not return until the page is completely loaded, so instead of getting incremental updates I simply get a long wait followed by a string of percentage values all at once.

Is there any way to get XMLHttpRequest to return or callback each time data is returned from the server (i.e. *before* the page has finished loading)? I had in mind something similar to a readline(), but don't know enough about JS to know what normal protocol is for this type of operation.

Cheers
 
Old 07-31-2009, 10:27 AM   #2
snoll
LQ Newbie
 
Registered: Jul 2009
Posts: 5

Rep: Reputation: 1
Quote:
I can get Apache/mod_python to return this information in real-time when the HTTP request is made, one update at a time, before returning.
That's your problem right there. Your mod_python page should only return a single value. You send an http request, and the mod_python script should only return the current status.

To get the effect of a progress/status bar, you need to put your loop in the javascript AJAX code. Have the javascript loop the AJAX request until an end-of-loop value is returned.

Doing AJAX by hand is a major PITA. You should take a look at one of the javascript frameworks like jquery or mootools. I haven't used mootools, but jquery makes AJAX a heck of a lot easier than trying to write it by hand and it also handles browser compatibility.

Have a look: http://docs.jquery.com/Ajax
 
  


Reply

Tags
ajax, javascript


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to run a ftp from c++ asynchronously perhaps using bash DEF. Programming 4 07-30-2009 12:12 PM
problem with ending requests asynchronously in my block device driver cable_plug2000 Programming 0 12-17-2007 01:44 AM
Why is my setTimeout(); (or maybe XMLHttpRequest();) not working in IE? farmerjoe Programming 1 07-17-2007 11:22 AM
Ubuntu Edgy/Firefox 2/Javascript - Firefox closes accessing websites with Javascript Interdictor Ubuntu 8 11-02-2006 11:58 AM
XmlHTTPRequest Question pnellesen Programming 1 09-19-2006 03:26 PM


All times are GMT -5. The time now is 04:45 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration