Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #11 (permalink)  
Old June 12th, 2008, 12:05 PM
Registered User
 
Join Date: Jun 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello again old friend and problem solver, Old Pedant

You are so smart. Your first suggestion about patience was right on the mark. I finally got my code straight so I think I understand it.

Maybe its not so much that I wasn't being patient, as much as I didn't know how to be patient? Six of one...........

It seems that not only alert() but other attempts to "pass some time" all fail to listen for the response (I may be stating that wrong) and so it never arrives. SetTimeout seems to be the only way, and Im fine with that, just still fuzzy about the concepts behind it. even a timeout set to 0 works. If you'd care to try and explain to me why the Ajax call acts this way, I'd greatly appreciate it. One reason I dont get it, is that the info seems to be at the browser allready cause it updates to the screen instantly.

I thank you heartily for your help and insights.

I am your grateful pupil,
oldBroh

  #12 (permalink)  
Old June 12th, 2008, 01:43 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

First of all: LOL! I finally realized you thought I meant that you, personally, had to be patient! Not at all; just meant that the *CODE* had to be patient! DOH on me.

Anyway... The reason that Ajax *CAN* work, at all, is that it is *NOT* using JavaScript code for the important part! It is using the XMLHTTP *component* (which in MSIE is a COM component; dunno how it is implemented in FireFox, but clearly not in JS code). So *THAT* component is capable of multithreading. And doing I/O. And releasing control until it receives a response from the server. And, finally, calling *BACK* into your JS code when the answer arrives.

So, yes, the data has already arrived from the server into the XMLHTTP component and the XMLHTTP component has actually already posted an event to the JavaScript code. So as soon as your JS code stops greedily holding onto the single thread--even if it just relinquishes its hold by doing a setTimeout [and yes, even with a zero-time timeout]--then *WHAM*, that event is allowed to actually invoke the JS code and you get the data in your JS function.

So... The secret is indeed multi-threading, just not multi-threading in JavaScript.

Make more sense?
  #13 (permalink)  
Old June 12th, 2008, 11:12 PM
Registered User
 
Join Date: Jun 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes sir, it makes good sense. Now if I only knew enough to truly understand it.

Thanks again for the help. Hope your around next time I get stuck







Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing javascript variable to html or php ashraf_gawdat Javascript How-To 3 July 12th, 2006 02:48 PM
Passing data from PHP to Javascript youngj PHP How-To 4 February 22nd, 2006 11:55 PM
Passing PHP variables to javascript wfrisch Pro PHP 10 April 5th, 2005 05:13 AM
passing php variable to javascript and vice versa onmcv Beginning PHP 0 March 24th, 2005 01:00 PM
passing javascript to php by Snib ismnanie Pro PHP 5 February 4th, 2005 07:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.