DrStrangeLove
DrStrangeLove

Reputation: 11577

difference between GET requests?

There're two GET requests:

1) "usual"GET (involves reloading page).

2) ajax GET (sync, async) background request.

What is difference between them?? Does HTTP standard make a distinction bitween them??

Upvotes: 0

Views: 426

Answers (2)

T.J. Crowder
T.J. Crowder

Reputation: 1075755

No, the HTTP standard makes no distinction between them. The distinction is applied at the browser level.

Fundamentally, the big difference is that a request via XMLHttpRequest (an "ajax" request) is subject to the Same Origin Policy. A normal GET is not. This means that in the normal case, you can't use a genuine "ajax" request to retrieve a resource from a different "origin" than the page on which your script is running. (Note that it's the origin of the page on which your script is running, not the origin of your script file, which can be from anywhere.)

There are ways in which "ajax" can be used even cross-origin:

  • Cross Origin Resource Sharing (CORS) is a new(ish) technology defined by the W3C and implemented by some browsers. It allows the resource being requested to make the decision of whether to allow itself to be used by the requesting document. Supported by the latest versions of all major browsers, though IE's support is broken requires that you use their proprietary XDomainRequest object rather than XMLHttpRequest.
  • JSON-P works around the restriction by not really being an "ajax" request at all; instead, it's a convention both the client and server observe that allows the client to include a script from the server via a script element. (The script in question is usually dynamically generated, and its sole job is to deliver a JavaScript object as a payload by calling a function.)

Upvotes: 1

GolezTrol
GolezTrol

Reputation: 116190

No. There is no difference. Although some browsers, and some frameworks like jQuery send an additional header, so you can make a distinction if you like. Otherwise they are handled the same.

Upvotes: 2

Related Questions