Anant
Anant

Reputation: 59

jQuery $.post();

I have a question about $.post() in jQuery. the general syntax is :

jQuery.post( url, [ data ], [ success(data, textStatus, XMLHttpRequest) ], [ dataType ] );

I'd be grateful if someone could shed light on what exactly data,textStatus are along with an example if possible

Thanks!

Upvotes: 3

Views: 1016

Answers (3)

Vivin Paliath
Vivin Paliath

Reputation: 95488

data is the response you get back from the server. It depends on the dataType that you specify. If you specify json as the argument to the dataType parameter, jQuery will interpret the data received from the server as json.

textStatus gives you information about the response, as in whether it was successful, or if something bad happened. Possible values are:

  • success
  • error
  • notmodified
  • timeout
  • parsererror

If your success handler is called, then the value of textStatus is most likely success.

You will get a parsererror if the data is of an unexpected type. For example, if you specified that dataType is json, but the server returned XML, you will get a parsererror and your error handler will be called.

Upvotes: 2

Chris Thompson
Chris Thompson

Reputation: 35598

According to http://api.jquery.com/jQuery.post/, the comments are correct

The success callback function is passed the returned data, which will be an XML root element or a text string depending on the MIME type of the response. It is also passed the text status of the response.

Upvotes: 1

Yves M.
Yves M.

Reputation: 3318

And if you are looking for a .NET version...

http://encosia.com/2009/04/07/using-complex-types-to-make-calling-services-less-complex/

Upvotes: 0

Related Questions