tags:

views:

52

answers:

3
+2  Q: 

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!

A: 

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

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

Yves M.
This link doesn't deal with the arguments to the success function in post, just post itself.
KLee1
+2  A: 

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.

Vivin Paliath
Is there a link that describes this? I couldn't find anything in the JQuery docs myself.
KLee1
@KLee1 oops - forgot to link to the source. I've edited my answer. I'm assuming that you're talking about `textStatus`?
Vivin Paliath
@Vivin yep. That's what I was looking for. +1
KLee1
+1  A: 

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.

Chris Thompson