开发者

How do I use alert() for errors?

开发者 https://www.devze.com 2023-01-20 05:21 出处:网络
How do I alert() an error when my server code returns false? $(\"#editme1\").editInPlace({ url: \'server.php\',

How do I alert() an error when my server code returns false?

  $("#editme1").editInPlace({
    url: 'server.php',
    error_sink: function(editme1, erro开发者_StackOverflow中文版rString) { alert(errorString); } <----Maybe this?
  });


what do you want to do exactly , if you are using ajax to call server side you can do in the error block. see the documentation here http://api.jquery.com/jQuery.ajax/


You can use the error callback, like this:

$("#editme1").editInPlace({
  url: 'server.php',
  error: function(xhr) { alert("Server error: " + xhr.responseText); }
});

Unfortunately the author didn't do a very good job here, he ignored the other very useful parameter error parameters on the $.ajax() error callback (textStatus and errorThrown).

So instead of using his error callback at all I'd use the global .ajaxError() handler, for example:

$(document).ajaxError(xhr, options, error) {
  alert("An error occured when fetching content: " + error);
});

Then don't specify anything in the plugin options for this:

$("#editme1").editInPlace({ url: 'server.php' });
0

精彩评论

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

关注公众号