how does an Ajax request differ from a normal browser reques

everybody. This question has been bugging me for a while;Is there a difference in how a web page is called and loaded when called through an Javascript AJAX request, instead of a direct browser request?(i.e., do requests look different from the server-side, and are answers handled differently on the client/browser side?)……………

via HTML Language Development » Search Results » ajax:

how does an Ajax request differ from a normal browser reques

everybody. This question has been bugging me for a while;
Is there a difference in how a web page is called and loaded when called through an Javascript AJAX request, instead of a direct browser request?
(i.e., do requests look different from the server-side, and are answers handled differently on the client/browser side?)
……………………………………….

An AJAX request is identical to a “normal” browser request as far as the server is concerned other than potentially slightly different HTTP headers. e.g. chrome sends:
X-Requested-With:XMLHttpRequestI’m not sure if that header is standardized or not, or if it’s different in every browser or even included at all in every browser.

edit: I take that back, that header is sent by jQuery (and likely other JS libraries), not the browser as is evidenced by:
var xhr = new XMLHttpRequest();
xhr.open(‘GET’, ‘/’);
xhr.send();which sends:
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie: ….
Host:stackoverflow.com
If-Modified-Since:Sat, 31 Dec 2011 01:57:24 GMT
Referer:http://stackoverflow.com/questions/8685750/how-does-an-ajax-request-differ-from-a-normal-browser-request/8685758
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11which leads me to the conclusion that by default there is absolutely no difference.
……………………………………….

There may be some header differences, but the main behavior difference is on the client.
When the browser makes a regular request as in window.location.href = “index.html”, it clears the current window and loads the server response into the window.
With an ajax request, the current window/document is unaffected and javascript code can examine the results of the request and do what it wants to with those results (insert HTML dynamically into the page, parse JSON and use it the page logic, parse XML, etc…).
The server doesn’t do anything different – it’s just in how the client treats the response from the two requests.
……………………………………….

Although I believe you guys, there is domething totally weird on weblogic: I am writing an app using ExtJS framework which does AJAX calls.
While doing the j_security_check, I always get errors when doing it the AJAX way: Weblogic says: unauthorized:var submitButton = new Ext.Button( text: ‘Logon’, formBind: true, //only enabled once the form is valid disabled: true, handler: function()
Ext.Ajax.request( url: “j_security_check”, params: j_username: dlg.getForm().findField(‘j_username’).getValue(), j_password: dlg.getForm().findField(‘j_password’).getValue() , method: “GET” }); } });
This fails.
When I issue this:
window.location.href = “j_security_check?j_username=” + dlg.getForm().findField(‘j_username’).getValue() + “&j_password=” + dlg.getForm().findField(‘j_password’).getValue();It works! Weird.
……………………………………….

your user-agent, aka browser, sends an XHR header which you can catch from php like this:
$_SERVER[‘HTTP_X_REQUESTED_WITH’]
……………………………………….

Not really. Except that most Ajax clients send a X-Requested-With=XMLHttpRequest HTTP header

For more info: how does an Ajax request differ from a normal browser reques

HTML Language Development » Search Results » ajax

how does an Ajax request differ from a normal browser reques

Share this post:

Related Posts

Leave a Comment