473,795 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how does ajax affect execution of code

If I have code that looks like this

ajax = function(str) {
var val = "";
// do some stuff here
return val;
};

var foo = ajax("string");
Does execution continue before a value is assigned to foo?

Andrew Poulos
Aug 18 '08 #1
7 1576
Andrew Poulos wrote:
If I have code that looks like this

ajax = function(str) {
var val = "";
// do some stuff here
return val;
};

var foo = ajax("string");
This doesn't seem to have anthing to do with Ajax aside from your choice of
variable name.
Does execution continue before a value is assigned to foo?
Continue from where?

The current code assigns a function to a variable (declared without var)
called 'ajax'. It immediately calls that function passing in the
argument "string". Next it assigns an empty string to a variable 'val', and
then returns that variable (assinging it to a variable called 'foo').

There is nothing odd about the timing of this.

(If XMLHttpRequest was involved, then the timing might get interesting, but
it isn't).
--
David Dorward
http://dorward.me.uk/
http://blog.dorward.me.uk/
Aug 18 '08 #2
Andrew Poulos meinte:
If I have code that looks like this

ajax = function(str) {
var ajax = ... might be smarter.
var val = "";
// do some stuff here
return val;
};

var foo = ajax("string");
Does execution continue before a value is assigned to foo?
In this very example? No.

Do you know what ajax or - to be more precise - "XHR" is?

Gregor
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Aug 18 '08 #3
Gregor Kofler wrote:
Andrew Poulos meinte:
>If I have code that looks like this

ajax = function(str) {

var ajax = ... might be smarter.
If ajax was not declared earlier.
> var val = "";
// do some stuff here
return val;
};

var foo = ajax("string");
Does execution continue before a value is assigned to foo?

In this very example? No.

Do you know what ajax or - to be more precise - "XHR" is?
Sorry I was saving space by only including what I thought was relevant
code. Please assume that within the function assigned to the variable
"ajax" are all the relevant XMLHttpRequest bits and pieces.

If I reword the question to, while we're waiting for something to return
from an XMLHttpRequest does execution of the javascript code continue?

If it does what happens when the event onreadystatecha nge has a
readyState equal to 4? Does execution stop whenever its up to and run
the code under the onreadystatecha nge function?

Andrew Poulos

Aug 18 '08 #4
On Aug 18, 10:18 am, Andrew Poulos wrote:
Gregor Kofler wrote:
>Andrew Poulos meinte:
>>If I have code that looks like this
>>ajax = function(str) {
>var ajax = ... might be smarter.

If ajax was not declared earlier.
>> var val = "";
// do some stuff here
return val;
};
>>var foo = ajax("string");
>>Does execution continue before a value is assigned to foo?
>In this very example? No.
>Do you know what ajax or - to be more precise - "XHR" is?

Sorry I was saving space by only including what I thought was
relevant code. Please assume that within the function assigned
to the variable "ajax" are all the relevant XMLHttpRequest
bits and pieces.
So should we be assuming that the XML HTML requests are being made
synchronously or asynchronously?
If I reword the question to, while we're waiting for something
to return from an XMLHttpRequest does execution of the javascript
code continue?
To which the answer is yes or no, depending on how you make the XML
HTTP request.
If it does what happens when the event onreadystatecha nge
has a readyState equal to 4?
If anything is going to happen when the readyState equals 4 then "it"
must do whatever is done.
Does execution stop whenever its up to and run
the code under the onreadystatecha nge function?
Execution stops and code runs? That seems a bit contradictory. Are you
asking whether events interrupt already executing code? They don't.
Aug 18 '08 #5
Andrew Poulos meinte:
Sorry I was saving space by only including what I thought was relevant
code. Please assume that within the function assigned to the variable
"ajax" are all the relevant XMLHttpRequest bits and pieces.
Ah a guessing game. Synchronous calls or asynchronous? In the latter
case: Once the request is sent, the skript moves on - therefore you need
a callback function to access the information returned from the server.
>
If I reword the question to, while we're waiting for something to return
from an XMLHttpRequest does execution of the javascript code continue?
If I'd have to wait: What would this XHR fuss all be good for? You (or
rather your script) normally doesn't wait. See above.
If it does what happens when the event onreadystatecha nge has a
readyState equal to 4? Does execution stop whenever its up to and run
the code under the onreadystatecha nge function?
Depends on what you mean by "execution stops". If it helps: JS is single
threaded.

Gregor
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Aug 18 '08 #6
Gregor Kofler wrote:
Andrew Poulos meinte:
>Sorry I was saving space by only including what I thought was relevant
code. Please assume that within the function assigned to the variable
"ajax" are all the relevant XMLHttpRequest bits and pieces.

Ah a guessing game. Synchronous calls or asynchronous? In the latter
case: Once the request is sent, the script moves on - therefore you need
a callback function to access the information returned from the server.
Thanks I didn't know they could be synchronous.
>If I reword the question to, while we're waiting for something to
return from an XMLHttpRequest does execution of the javascript code
continue?

If I'd have to wait: What would this XHR fuss all be good for? You (or
rather your script) normally doesn't wait. See above.
>If it does what happens when the event onreadystatecha nge has a
readyState equal to 4? Does execution stop whenever its up to and run
the code under the onreadystatecha nge function?

Depends on what you mean by "execution stops". If it helps: JS is single
threaded.
Sorry, its obvious that I'm having trouble understanding ajax concepts.

I can get a value returned by a server using ajax. How do you handle the
situation where subsequent ajax calls are dependent upon the value
returned from previous calls? As I don't know when those values will return.

Andrew Poulos
Aug 19 '08 #7
Andrew Poulos meinte:
I can get a value returned by a server using ajax. How do you handle the
situation where subsequent ajax calls are dependent upon the value
returned from previous calls? As I don't know when those values will
return.
Those subsequent XHR calls are triggered in the response callback function.

Pseudo:

xhr.onreadystat echange = function() {
if (xhr.readystate === 4) {
foo(xhr.respons eText);
}
}
var foo = function(respon seText) {
trigger another XHR request;
}
Gregor
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Aug 19 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
4863
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it can be done using the designer but I intentionally don't want to use that. The one reason is that you cannot change the code generated by the designer. The other could be that you have more free hand and control to design your GUI. 2....
113
5314
by: John Nagle | last post by:
The major complaint I have about Python is that the packages which connect it to other software components all seem to have serious problems. As long as you don't need to talk to anything outside the Python world, you're fine. But once you do, things go downhill. MySQLdb has version and platform compatibility problems. So does M2Crypto. The built-in SSL support is weak. Even basic sockets don't quite work right; the socket module...
9
4862
by: dougloj | last post by:
Hi. I have an ASP.NET application written in C#. In part of my application, I want to use JavaScript OnClick event function to update a textbox with a string generated asynchronously on the server. I have pretty much figured out two ways to this. One way involves AJAX. The other way involves using cookies. I think AJAX is awesome, but what if the user's browser blocks ActiveX controls? On the other hand what if the browser blocks...
8
2582
by: =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?= | last post by:
I am new to AJAX. I am applying AJAX to a current web solution to get the "instant behaviour". On my main page I have two sets of criteria: Specific and Wide. Each set is placed in a View container. I am not sure that I configured the Triggers correct, but the behaviour is OK. When I click the linkbuttons they switch between two sets of search controls. When I click the search buttons they reload the display panel. BUT .... if the...
5
22585
by: pbd22 | last post by:
Hi. I am having a hard time figuring this one out... I have a sign in page. in my sign in logic, the successful login uses forms authentication and assigns an HttpCookie for the site-wide "user id" (ie. "Welcome BillG ! "). when the user clicks on "signout" from any given page, an XMLHttp call queries a server script (VB.NET) which
3
2834
by: Mukesh | last post by:
Hi all I have Created an web application using VS 2005, asp.net2.0, Ajax Extensions 1.0, Ent Lib 3.1 , MS sql Server 2005, ajax Control tool kit Version 1.0.10618.0
12
4810
by: lali.b97 | last post by:
Somewhere in a tutorial i read that if statement has performance overheads as code within the if statement cannot take benefit of pipeling of microprocessor and also that the compiler cannot agressively optimize that code. my functions as much as possible and also try to have minimum code withing if block.
2
5539
by: =?Utf-8?B?REo=?= | last post by:
I have a peculiar problem here that I did not have until I migrated from ASP.NET 2.0 to 3.5. I use a master page for my application. Because the master page uses update panels I have the scriptmanager control on the master page. Any pages in the app that uses the master page under 2.0 automatically used that script manager if any AJAX controls were involved. Everything was well with the world and we all sang ohmmmmmmmmmmmm.... After...
29
3326
by: zalek | last post by:
I am writing application with Ajax in sync mode - xmlHttp.open("GET", url, false). I noticed that in FireFox handler doesn't starts. It starts when I use xmlHttp.open("GET", url,true). I need to use it in sync mode. Any ideas what can I do? Thanks, Zalek.
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.