我有一个链接,点击这个链接,ajax POST请求就会启动。我这样做:
$('a#create_object').click();这将触发一个ajax请求。这个($.ajax({...}))的代码写在bootstrap libs中的某个地方,我不想编辑thwem。
如何在ajax成功后访问请求的响应?
发布于 2013-04-25 21:02:09
直接回调从jQuery 1.8.0开始就被弃用了,但您可以使用.done、.fail和.always回调!
如果你想做一些事情,你必须覆盖/访问回调,我是说你不能从外部访问它!
$('#link').on('click', function(e) {
$.ajax({
type: "post",
url: "your-page",
data: {},
dataType: "json"
}).done(function (response) {
alert('Success');
console.log(response); // Use it here
}).fail(function (response) {
alert('Fail');
console.log(response); // Use it here
}).always(function (response) {
// Here manage something every-time, when it's done OR failed.
});
});发布于 2013-04-25 21:01:16
$('#controlId').click(function(){ $.ajax({
type: "POST",
url: "PageUrl/Function",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d); //here you can get the response on success of function
}
});
});https://stackoverflow.com/questions/16215347
复制相似问题