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
- Also is the code written as callback for load()..e.g. load(url,function(){});
same as what is mentioned under success or ajaxSuccess..I mean will the callback function code not exectuted at the same time as the success or ajaxSuccess ?
Thnak you.
1) you need to understand HTTP.
getandpostmake “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)
successfires on success, i.e. if the response returns a 200.completealways 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,
beforeSendis fired before the actual underlying ajax request is invoked. The documentation says things like “Use this to set custom headers, etc.”