whats wrong with this getJson call
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 success开发者_如何学JAVAful 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();
});
You should actually get a syntax error. Remove complete:
:
$.getJSON('/users/delete_preapproval', {
preapproval: $(this).attr('id'),
id: $(this).attr('id')
},
function(data) {
console.log('ssss');
});
complete:
is creating a label [docs] at this line. Removing the label would be:
function(data) {
function(){
console.log('ssss');
}
}
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:
$.getJSON('/users/delete_preapproval', {
preapproval: $(this).attr('id'), id: $(this).attr('id') },
function(data) {
console.log(data);
});
Why don't you try
$.ajax({
type: 'post',
url: "/users/delete_preapproval",
dataType: 'json',
data: {preapproval : $(this).attr('id'), id : $(this).attr('title')},
complete: function () {
console.log('ssss');
}
});
That should work...
精彩评论