这个 getJson 调用有什么问题
这是我的 jQuery
$.getJSON('/users/delete_preapproval', {
preapproval: $(this).attr('id'), id: $(this).attr('id') },
function(data) {
complete: function(){
console.log('ssss');
}
});
All 运行良好,服务器处理请求,但完整的不起作用...我没有显示我的 console.log。我基本上需要在成功的 ajax 调用后触发完成或成功
编辑:这是我的整个点击事件:
$('.delete_preapproval').click(function(e){
var count = $(this).closest('.request_count').attr('data');
if(count > 0){
if(count == 1){
var plural = 'request';
}else{
var plural = 'requests';
}
if (confirm('Are you sure you want to delete this preapproval you have ' + count + ' active ' + plural)){
$.getJSON('/users/delete_preapproval', {
preapproval: $(this).attr('id'),
id: $(this).attr('id')
},
function(data) {
console.log('ssss');
});
}else{
return false;
}
}else{
$.getJSON('/users/delete_preapproval', { preapproval: $(this).attr('id'), id: $(this).attr('id') }, function(data) {
window.location.reload();
});
}
e.preventDefault();
});
here is my jQuery
$.getJSON('/users/delete_preapproval', {
preapproval: $(this).attr('id'), id: $(this).attr('id') },
function(data) {
complete: function(){
console.log('ssss');
}
});
All works well and the server processes the request but the complete is not working...I am not getting my console.log displaying. I basically need an on complete or on success to fire after a successful ajax call
EDIT: here is my entire click event:
$('.delete_preapproval').click(function(e){
var count = $(this).closest('.request_count').attr('data');
if(count > 0){
if(count == 1){
var plural = 'request';
}else{
var plural = 'requests';
}
if (confirm('Are you sure you want to delete this preapproval you have ' + count + ' active ' + plural)){
$.getJSON('/users/delete_preapproval', {
preapproval: $(this).attr('id'),
id: $(this).attr('id')
},
function(data) {
console.log('ssss');
});
}else{
return false;
}
}else{
$.getJSON('/users/delete_preapproval', { preapproval: $(this).attr('id'), id: $(this).attr('id') }, function(data) {
window.location.reload();
});
}
e.preventDefault();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你实际上应该得到一个语法错误。删除
complete:
:complete:
正在创建一个 在这一行添加标签[docs]。删除标签将是:您会看到,当调用外部函数时,内部函数永远不会执行(除了语法错误之外)。
更新:还要确保您返回的数据是正确的 JSON。否则 jQuery 无法解析它并且不会调用回调。
You should actually get a syntax error. Remove
complete:
:complete:
is creating a label [docs] at this line. Removing the label would be:You see that that inner function is never executed when the outer function is called (apart from the syntax error).
Update: Also make sure that the data you return is proper JSON. Otherwise jQuery cannot parse it and will not call the callback.
您需要删除完整的:及其后面的函数调用。所以更像是:
You need to remove the complete: and the function call after it. So something more like:
你为什么不尝试一下
那应该可行...
Why don't you try
That should work...