我正在学习如何将MVC Ajax转换为jquery ajax,以便我可以做更多。将MVC Ajax转换为jquery
这是老阿贾克斯,我拿出装东西
@Ajax.ActionLink("Update Tweets", "Index", "Home",
new AjaxOptions
{
UpdateTargetId = "TweetBox",
InsertionMode = InsertionMode.InsertBefore,
HttpMethod = "Get",
})
我需要将其转换为jQuery的阿贾克斯。它似乎在工作,让我们看看代码
<script>
$(document).ready(function() {
$("#StartLabel").click(function (e) {
$.ajax({
type: "Get",
url: '/Home/Index',
// data: "X-Requested-With=XMLHttpRequest",
// contentType: "application/text; charset=utf-8",
dataType: "text",
async: true,
// cache: false,
success: function (data) {
$('#TweetBox').prepend(data);
alert('Load was performed.');
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
},
complete: function (resp) {
alert(resp.getAllResponseHeaders());
}
});
});
});
</script>
在微软AJAX它设置标头中的XML请求。我需要添加吗?我只是分页我的控制器,执行一个查询到twitter并将数据追加到顶部。
我使用小提琴来查看请求是如何不同,但结果是相同的。
我也注意到,如果我把文本放在data:object中,它会把它放在标题中。我不认为这是正确的。
让我掏更深一点。我需要实现jnoifier插件和定时器/彗星式反向ajax解决方案,但我正在建设中。当我建议我使用jQuery Ajax时,我决定使用jnotifier,因为我实现了额外的功能。 – 2012-04-04 17:21:14