doujiao4710 2011-08-31 08:26
浏览 70
已采纳

使用jquery ajax处理服务器端验证的最佳方法

$('form[id^=comment_add]').live("submit",function()
{
    var id= this.id.replace(/[^\d]+/g,'');      
    $.post($(this).attr('action'), $("#comment_add"+id).serialize(), function(data)
    {
        /*do something*/
    })
    .error(function(jqXHR, textStatus, errorThrown)
    {
        displayError(errorThrown, id);
    });
    reloaded();
    return false;
});

Currently i am throwing a HTTP error with the response containing the json string. and then parsing the json string and showing the errors. Is this a good way or are there better ways. or which is the recommended way to display server side validation

  • 写回答

1条回答 默认 最新

  • dongzhoulong1797 2011-08-31 08:34
    关注

    Yes, it is good idea. Even StackOverflow throws different error codes when error appears. Use this one you're using

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable