在$。员额和$就不同? [英] Difference between $.post and $.ajax?
问题描述
好奇,如果有人知道的区别是关于数据参数的内容。
Curious if anyone knows what the difference is in regards to the data parameter.
我有一个 $。交
方法,需要一个 $('#MyForm的')。序列化()
因为我的数据参数和作品。
I have a $.post
method that takes a $('#myform').serialize()
as my data param and works.
如果我尝试同样使用 $。阿贾克斯()
的办法,它不工作,我的数据参数显示不正确。
If I try the same using the $.ajax()
approach, it doesn't work as my data param doesn't appear correct.
有谁知道其中的差别,我可能会使用的东西,而不是上述 .serialize()
?
Does anyone know the difference and what I might use instead of the above .serialize()
?
推荐答案
在重新阅读了一些在线文档,我决定跟$。员额坚持超过$阿贾克斯。
After re-reading some online documentation, I decided to stick with $.post over $.ajax.
在$阿贾克斯方法的数据参数做的东西比$。员额方法不同呢,不知道究竟是什么,但有一个区别。
The $.ajax method's data param does something different than the $.post method does, not sure what exactly, but there is a difference.
我想用$阿贾克斯的唯一原因是因为我希望能够来处理事件,并没有意识到我可以这样做与$。员额。
The only reason I wanted to use $.ajax is because I wanted to be able to handle events and didn't realize I could do so with $.post.
下面是我结束了
function GetSearchItems() {
var url = '@Url.Action("GetShopSearchResults", "Shop", New With {.area = "Shop"})';
var data = $("#ShopPane").serialize();
// Clear container
$('#shopResultsContainer').html('');
// Retrieve data from action method
var jqxhr = $.post(url, data);
// Handle results
jqxhr.success(function (result) {
//alert("ajax success");
$('#shopResultsContainer').html(result.ViewMarkup);
});
jqxhr.error(function () {
//alert("ajax error");
});
jqxhr.complete(function () {
//alert("ajax complete");
});
// Show results container
$("#shopResultsContainer").slideDown('slow');
}
这篇关于在$。员额和$就不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!