Lawrence Avery
asked on
Asynchronous Javascript (AJAX)
I am a little confused. When is XML returned versus JSON from the web server when a client browser
makes an asynchronous?
I see example of making a call to a WCF with the JSON returned to the client.
http://dotnetbyexample.blogspot.com/2007/10/calling-asmx-web-services-directly-from.html
How is XML returned using the AJAX model versus JSON? Is it by using the XMLHttpRequest?
makes an asynchronous?
I see example of making a call to a WCF with the JSON returned to the client.
http://dotnetbyexample.blogspot.com/2007/10/calling-asmx-web-services-directly-from.html
How is XML returned using the AJAX model versus JSON? Is it by using the XMLHttpRequest?
ASKER
Can you list the modes AJAX can run in?
ASKER
I forget also, if it is synchronous, it can be a partial page update versus a full page.
That is in the AJAX Model.
That is in the AJAX Model.
those are the 2 modes it can run in, asynchronous and synchronous
here's a good article to read up on to further explain:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Synchronous_and_Asynchronous_Requests
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Synchronous_and_Asynchronous_Requests
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When I asked about listing the modes, what I really meant to ask is what are different ways of using the AJAX model. I know there is asynchronous and synchronous modes as far as how it is requesting something.
But I meant how many ways are there to represent the AJAX model.
Here is what I came up with:
Using the 1 XMLHttpRequest object to make a asynchronous call
2. jQuery functional call ----- $().ajax
3. Using the UpdatePanel
Am I right in saying the ways of representing the AJAX Model????
BTW the article you attached is great. Thank you.
But I meant how many ways are there to represent the AJAX model.
Here is what I came up with:
Using the 1 XMLHttpRequest object to make a asynchronous call
2. jQuery functional call ----- $().ajax
3. Using the UpdatePanel
Am I right in saying the ways of representing the AJAX Model????
BTW the article you attached is great. Thank you.
ASKER
Also in using the xmlHttpRequest (see below the code):
xmlhttp.open("POST","ajax_test.asp",true);
xmlhttp.setRequestHeader(" Content-ty pe","appli cation/x-w ww-form-ur lencoded") ;
xmlhttp.send("fname=Henry& lname=Ford ");
why would you use a URL asp.net webpage when asynchronously calling ?
See attached link http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp
xmlhttp.open("POST","ajax_test.asp",true);
xmlhttp.setRequestHeader("
xmlhttp.send("fname=Henry&
why would you use a URL asp.net webpage when asynchronously calling ?
See attached link http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp
ASKER
I just realized the location ajax_test.asp is not an .aspx page.
So I guess when they ask for ajax_test_asp, they're just asking for content not to execute the page on the server,
right?
So I guess when they ask for ajax_test_asp, they're just asking for content not to execute the page on the server,
right?
I'll try to address your questions point by point here:
as long as you understand the very basic foundation of how ajax works, the rest of it should fall into place. the underlying process works like this: a page is fully loaded (doesn't matter if it's html, php, or aspx), and upon a certain user action (say a button click), a call is then made "behind the scenes" back to the web server. Depending on the specifics of that call, it may or may not receive data back, if it does, javascript code will then process that data, which could mean updating part of the screen. All of this is done without the page refreshing.
The 3 scenarios you listed above are all ways to make an ajax call, in fact, the second two are just wrappers for the first one. jquery is just a javascript library that makes working with javascript a lot easier. I'm not all that familiar with UpdatePanels, my basic understanding of them is they allow certain parts of your page to be able to work with ajax more easily in .NET pages. Keep in mind there are other ways to make ajax calls, but I would just concentrate on the first two you have listed for now as they are the most common.
whenever you make an ajax call, you always have to specify WHERE to make that call to. It's no different than setting a forms ACTION attribute, it just needs somewhere to handle the call, otherwise you'll get a 404 page not found error
sort of. like I explained above, a page is needed to handle the ajax call, otherwise it won't know what to do. it doesn't necessarily have to display content, for example, you could have a page that keeps track of how many times a specific link is clicked.when the user clicks that link, an ajax call could be made to update the database to keep track of the number of clicks for that link. The user would never see anything on the screen indicating this, but the ajax call would still be made.
hope I answered all of your questions!
When I asked about listing the modes, what I really meant to ask is what are different ways of using the AJAX model. I know there is asynchronous and synchronous modes as far as how it is requesting something.
But I meant how many ways are there to represent the AJAX model.
Here is what I came up with:
Using the 1 XMLHttpRequest object to make a asynchronous call
2. jQuery functional call ----- $().ajax
3. Using the UpdatePanel
Am I right in saying the ways of representing the AJAX Model????
as long as you understand the very basic foundation of how ajax works, the rest of it should fall into place. the underlying process works like this: a page is fully loaded (doesn't matter if it's html, php, or aspx), and upon a certain user action (say a button click), a call is then made "behind the scenes" back to the web server. Depending on the specifics of that call, it may or may not receive data back, if it does, javascript code will then process that data, which could mean updating part of the screen. All of this is done without the page refreshing.
The 3 scenarios you listed above are all ways to make an ajax call, in fact, the second two are just wrappers for the first one. jquery is just a javascript library that makes working with javascript a lot easier. I'm not all that familiar with UpdatePanels, my basic understanding of them is they allow certain parts of your page to be able to work with ajax more easily in .NET pages. Keep in mind there are other ways to make ajax calls, but I would just concentrate on the first two you have listed for now as they are the most common.
Also in using the xmlHttpRequest (see below the code):
xmlhttp.open("POST","ajax_test.asp", true);
xmlhttp.setRequestHeader("Content-ty pe","appli cation/x-w ww-form-ur lencoded") ;
xmlhttp.send("fname=Henry&lname=Ford ");
why would you use a URL asp.net webpage when asynchronously calling ?
whenever you make an ajax call, you always have to specify WHERE to make that call to. It's no different than setting a forms ACTION attribute, it just needs somewhere to handle the call, otherwise you'll get a 404 page not found error
I just realized the location ajax_test.asp is not an .aspx page.
So I guess when they ask for ajax_test_asp, they're just asking for content not to execute the page on the server,
right?
sort of. like I explained above, a page is needed to handle the ajax call, otherwise it won't know what to do. it doesn't necessarily have to display content, for example, you could have a page that keeps track of how many times a specific link is clicked.when the user clicks that link, an ajax call could be made to update the database to keep track of the number of clicks for that link. The user would never see anything on the screen indicating this, but the ajax call would still be made.
hope I answered all of your questions!
ASKER
When you say that ajax calls doesn't care what the goal is, ultimately its just making a call to the server without refreshing the page.
So are you saying if the url specified is a webpage, the webpage is executed but the output is placed in Response text of the xmlHttpRequest.
And the javascript does what it wants with it?
So are you saying if the url specified is a webpage, the webpage is executed but the output is placed in Response text of the xmlHttpRequest.
And the javascript does what it wants with it?
exactly.
I do a lot of classic asp development, and when I incorporate ajax into my page, I'll often make the url the same page and append it with a query string, like this:
somePage.asp?mode=1
and in my code that handles the ajax call, I'll do an IF statement checking for that query string value:
if Request.QueryString("mode" ) = "1" then
'-- processing ajax call
Response.End
end if
the Response.End line stops the page from loading any more, so I don't get any other html written back ResponseText property, thus making it a lot easier to manipulate it the way I want. If it's a complex response I'm getting back, I'll make the ajax processing code it's own page
I do a lot of classic asp development, and when I incorporate ajax into my page, I'll often make the url the same page and append it with a query string, like this:
somePage.asp?mode=1
and in my code that handles the ajax call, I'll do an IF statement checking for that query string value:
if Request.QueryString("mode"
'-- processing ajax call
Response.End
end if
the Response.End line stops the page from loading any more, so I don't get any other html written back ResponseText property, thus making it a lot easier to manipulate it the way I want. If it's a complex response I'm getting back, I'll make the ajax processing code it's own page
ASKER
Can a URL be a .aspx file? If so, do you use the Response object in the aspx page to write back out to the ResponseText.
yes. in theory, it can be ANY type of file.
yup, you can do that as well. Keep in mind that that's not the ONLY way to fill up the ResponseText variable, you could have a static html page for the url and the html in that page could be passed back to the ResponseText property as well
If so, do you use the Response object in the aspx page to write back out to the ResponseText.
yup, you can do that as well. Keep in mind that that's not the ONLY way to fill up the ResponseText variable, you could have a static html page for the url and the html in that page could be passed back to the ResponseText property as well
ASKER
What would happen if you didn't use the Response object in a aspx file? In other words, what would come back to the ResponseText property if you left out the Response object calls? Would it be the output from the page render phase of the aspx page?
yes
Open in new window
this would return json whether or not the call was asynchronous or synchronous