Johan
Johan

Reputation: 35194

ajax GET/POST, what is actually being sent?

$.ajax({ 
    url: 'somewhere.php',
    data: { foo: 'foo', bar: 'bar' }
});

I know that this would generate a get-string in firebug, similar to somepage.php?foo=foo&bar=bar

$.ajax({ 
    url: 'somewhere.php',
    data: { foo: 'foo', bar: 'bar' },
    type: 'POST'
});

And this would post a form with the values.

But is it a complete page that is being sent when using $.ajax()? Or is it just parts of a page?

Upvotes: 0

Views: 134

Answers (2)

Zbigniew
Zbigniew

Reputation: 27594

data parameter contains all the data you are sending, so it is not part of the page nor whole page (unless you make it so).

In your example you are sending two variables foo and bar, which are inside object, only difference here is method (get or post) of sending your data.

Upvotes: 2

Joost
Joost

Reputation: 4134

In the end it's just another HTTP request being sent. The parameters of your $.ajax() call define what the request looks like. You're not sending a page, much like you're not sending a page when you tell your browser to visit google.com by typing it in the address bar.

You are receiving a page, though. The difference between receiving a page via an ajax call and browsing to it is that it's not sent to your browser's render engine and displayed in its own window or tab, but the source of that page is simply sent to the callback functions you define in jQuery.

Upvotes: 2

Related Questions