【发布时间】:2012-04-04 16:19:30
【问题描述】:
我正在学习如何将 MVC Ajax 转换为 jquery ajax,以便我可以做更多。
这是旧的ajax,我把加载的东西拿出来了
@Ajax.ActionLink("Update Tweets", "Index", "Home",
new AjaxOptions
{
UpdateTargetId = "TweetBox",
InsertionMode = InsertionMode.InsertBefore,
HttpMethod = "Get",
})
我需要将其转换为 jquery ajax。它似乎正在工作让我们看看代码
<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>
在 microsoft ajax 中,它在标头中设置 XML 请求。我也需要添加吗?我只是在分页我的控制器,它对 twitter 执行查询并将数据附加到顶部。
我正在使用 fiddler 来查看请求有何不同但结果相同。
我还注意到如果我将文本放入数据中:对象将其放入标题中。我不认为这是对的。
【问题讨论】:
标签: ajax asp.net-mvc-3 jquery asp.net-ajax