Jquery help adding an ajax call
Please have a look at these two pieces of code. I am using jquery edit in place. This is the code that it uses and works.
$("#name").editInPlace({
url: 'test.php',
error: function() {
alert('error');
}
});
What I want to do is replace the alert with a div that will echo the error message instead. This next piece of code is one that I am using in a totally separate of the site. I'd like to use that same functionality in the code above if possible. Can someone please tell me if this is possible and how to do it?
$.ajax({
type: "POST",
url: "post.php",
dataType: 'json',
success: fu开发者_开发百科nction(data){
var div = $('<div>').attr('id', 'message').html(data.message);
if(data.success == 0) {
$(div).addClass('ajax-error');
} else {
$(div).addClass('ajax-success');
}
}
});
Can't you just use it like this?
$.ajax({
type: "POST",
url: "post.php",
dataType: 'json',
success: function(data){
$(div).addClass('ajax-success');
},
error: function(data){
$(div).addClass('ajax-error');
}
});
精彩评论