x-editable 渲染 html 错误响应

x-editable render html error response

我们有一个可以在线编辑客户信息的系统。 当有人输入已经存在的电子邮件时,我想 return 错误消息:

Email already exists. <a href='/find-duplicates/id'>Click here to find possible duplicates of this customer</a>

我希望用户能够在 s/he 看到错误消息时单击 link。错误信息很容易发送;它正在渲染 html 这就是问题所在。

尝试在 x-editable 字段错误中显示与@iateadonut 相同的 link。

对于任何想在 x-editable 错误中显示 html 的人,假设您收到从服务器发回的 html 错误,响应状态代码不同于 500(可能是 400),请尝试:

$(function() {
  $('#your_field_id').editable({
    error: function(response, newValue) {            
        if(response.status === 500) {
            return 'Service unavailable. Please try later.';
        } else {
            var error = $.parseHTML( response.responseText )
            $(".editable-error-block").html(error)
        }
     },
  });
})

主要是 html 解析响应错误并将其注入到 x 可编辑错误块中。 在 x-editable doc, options.

中找到