tags:

views:

32

answers:

2

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: function(data){
    var div = $('<div>').attr('id', 'message').html(data.message);
    if(data.success == 0) {
      $(div).addClass('ajax-error');
    } else {
      $(div).addClass('ajax-success');
    }
  }
});
A: 

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');
  }  
});
etbal
A: 

I am the OP. I have tried etbal's suggestion but I get JavaScript errors. The error begins at $.ajax. Does anyone have sufficient knowledge of jquery to fix this? I can't imagine that I'm trying to do something out of the ordinary here.

jim