这个getJson调用有什么问题?
whats wrong with this getJson call
这是我的jQuery
$.getJSON('/users/delete_preapproval', {
preapproval: $(this).attr('id'), id: $(this).attr('id') },
function(data) {
complete: function(){
console.log('ssss');
}
});
一切正常,服务器处理请求,但完成不工作…我没有得到我的console.log显示。我基本上需要一个on complete或on success来触发一个成功的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();
});
您实际上应该得到一个语法错误。删除complete:
:
$.getJSON('/users/delete_preapproval', {
preapproval: $(this).attr('id'),
id: $(this).attr('id')
},
function(data) {
console.log('ssss');
});
complete:
在这一行创建了一个标签[docs]。删除标签将是:
function(data) {
function(){
console.log('ssss');
}
}
您可以看到,当调用外部函数时,内部函数永远不会执行(除了语法错误)。
Update:还要确保返回的数据是正确的JSON。否则,jQuery无法解析它,也不会调用回调。
您需要删除完整的:和它后面的函数调用。比如:
$.getJSON('/users/delete_preapproval', {
preapproval: $(this).attr('id'), id: $(this).attr('id') },
function(data) {
console.log(data);
});
你为什么不试试呢
$.ajax({
type: 'post',
url: "/users/delete_preapproval",
dataType: 'json',
data: {preapproval : $(this).attr('id'), id : $(this).attr('title')},
complete: function () {
console.log('ssss');
}
});
相关文章:
- 我不知道我的编码有什么问题.(JavaScript)
- 什么'这个javascript代码getElementById有问题
- 我的流星路线出了什么问题
- 此nodeValue替换代码有什么问题
- 这个正则表达式的日期/时间有什么问题
- 我的CSS/Javascript下拉菜单测试代码出了什么问题
- 这个代码出了什么问题?(Jquery)
- 下面的Reg表达式出了什么问题
- 鼠标事件,我的代码出了什么问题
- 这个javascript语法有什么问题
- 动态创建foreignGroup并将其添加到svg中有什么问题
- 此代码中动态生成选择框有什么问题
- 我的javascript有什么问题?.className
- 这个 ajax.js 代码有什么问题
- 框架的可用性问题是什么
- JS代码有什么问题,让我知道代码是否可以改进
- 我的 Browserify JavaScript 代码有什么问题
- 图像上传功能将++(+1)副本添加到下一次上传.出了什么问题或如何重置“选定图像”
- 使用 Javascript 动态删除行.我的代码有什么问题
- Ajax jQuery图片上传-新手问题什么是最好的方式来处理这个