what is difference between
$.ajax({
type: "POST",
url: "/LiveGame/Partial3?gameDate=" + dateText,
dataType: "html",
success: function(result) {
var domElement = $(result);
$("#dvGames").html(domElement);
}
});
and
onSelect: function(dateText, inst) {
$('#dvGames').load(
'<%= Url.Action("Partial3", "开发者_如何学PythonLiveGame") %>',
{ gameDate: dateText }
);
}
.ajax has lot of feature than .load... its support more than resulttype (json,xml.html) its has their own onerror callback
where as .load is limited to only html result, and it doesn't has their own onerror callback.
If you only want to retrieve HTML content from the remote script I'd tend to use .load()
since it's simpler. Also you can use jQuery selectors directly in the url
parameter to restrict the insertion to a specific HTML fragment.
See http://api.jquery.com/load/
Both are actually same. The second one $.load
is like shorthand for $.ajax
. If you want to have more control over the request parameters (like datatype, contenttype etc.) then $.ajax
is better option. On the other hand if you want to load some content (html from a request or service) simply call $.load
function with the URL from where to get the stuff and it will get it and render it in given element. Visit jQuery documentation page for more information.
$.get, $.post and $.load, all use $.ajax to send asynchronous call to the server. difference is that in specific calls ($.get, $.post, $.load) some parameters of $.ajax are fixed and as a result you can not send a post request using $.get or get request using $.post. similarly, u can not specify return type of json or xml when using $.load. control over success and error callbacks may also be limited when using specific methods. whereas, using $.ajax you have complete control over what u r sending and what u intend to receive and how u want to manipulate the result or error using callbacks.
.ajax is jQuery's "low" level implementation of remote scripting. Details can be found at jQuery's documentation.
Both are pretty much the same thing. .load()
is the shorthand use of $.ajax
. It is nor faster or slower since it's basically $.ajax
.
The advantage of $.load()
is that it's much simpler and straight forward to use if you are going to run a script or append returned data to an element. While $.ajax()
allows you to have more control over the Ajax call(such as xhr, contentType, etc. ). You can see a list of many useful options available to you here.
精彩评论