Ajax POST and GET.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Ajax POST and GET.

Post by JellyFish »

Hey, I'd like to elaborate on the differences in using POST or GET method for your HTTP requests with javascript's XMLHttpRequest object. For all I know, at the moment, the difference in that with php you'd use $_POST with POST methods and $_GET with GET methods.

Please explain in detail the concept, I'm a little confused on this on.

Thanks for reading.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

it's all about how / if you send data with your request.

When you do a GET request, you're only sending the URL, which can pass some limited data in it.

A POST request can send a whole chunk of data with it. Some people send XML, others send form encoded data.

General rule of thumb: If you're getting a update or something, use GET. If you're submitting data, use POST.

jquery has these functions built in, and their descriptions might help clear things up: http://www.visualjquery.com/1.1.1.html
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

So which method would you recommend for a login form and a simple error message (like "Forgot to enter your password")?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I'm sure login is always best to use post, regardless of your medium. Would you want your login information on screen as a friend walks by?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I don't think it really matters with small data like that, but I almost exclusively use POST anyway.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Okay, is there any difference syntactically with POST?
Post Reply