Reputation: 50722
I have a few questions on jQuery AJAX.
It is confusing to understand why there are multiple methods like load(), get(), post()..is the diff only like $.ajax is general way of writing and others being specific based on type..?
I do not cleatly understand the diff between complete, success..Are they similar or is there any diff as to when each should be used ?
In terms of script execution from within an HTML response, does jQuery AJAX handle it automatically OR do we need to specify something like eval() ? Also how diff is this behavior compared to a normal AJAX only handling?
Regarding the beforeSend , is it similar to ajaxSetup and generally speaking, what are the common attributes which are used out of the many which are availbale?
Edited
Thnak you.
Upvotes: 2
Views: 101
Reputation: 120168
1) you need to understand HTTP. get
and post
make "GET" and "POST" requests, respectively, which is useful if you are building a RESTful service. EDIT: I actually don't see get and post methods on the ajax object; you pass a 'type' parameter to specify the HTTP method you want to use.
2) success
fires on success, i.e. if the response returns a 200. complete
always fires after everything else is done.
3) Ideally, your server would return json. If you configure the Ajax call to expect json, then it will parse it for you.
4) The documentation is very clear, beforeSend
is fired before the actual underlying ajax request is invoked. The documentation says things like "Use this to set custom headers, etc."
Upvotes: 11
Reputation: 6273
complete
is fired after every request is complete, while success
only fires if there were no errors (a successfully onesuccess
callback areabeforeSend
is called right before the ajax request is firedUpvotes: 0