开发者

Jquery help adding an ajax call

开发者 https://www.devze.com 2023-01-20 01:05 出处:网络
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.

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');
  }  
});
0

精彩评论

暂无评论...
验证码 换一张
取 消