表单序列化在ajax post与ckeditor抛出ajax错误

form serialize in ajax post with ckeditor throws ajax error

本文关键字:ajax ckeditor 抛出 错误 post 序列化 表单      更新时间:2023-09-26

我在我们的项目中使用ckeditor。在ajax post中传递该值,如

   //$form is -> $('form') jquery object     
    $("#ajaxsubmitbutton").on('click', function () {
      CKupdate();
    $.ajax({
                        type: ($form.attr('method').toLowerCase() == 'post' ? 'POST' : 'GET'),
                        url: ($form.attr('action') == 'undefined' ? window.location : $form.attr('action')),
                        data: $form.serialize(),
                        success: function (data) {
                            // Use local eval, since it will work in this context
                            callbackFunction(data);
                        },
                        error: function () {
                            var data = "ajaxerror";
                            callbackFunction(data);
                        }
                    });
});

Ckeditor更新代码:

function CKupdate(){
        for ( instance in CKEDITOR.instances )
            CKEDITOR.instances[instance].updateElement();
      }

美元形式。

"Id=0&Title=dfg&ShortText=rer&CultureCode=en-US&StartDate=3%2F12%2F2014&EndDate=3%2F26%2F2014&Text=%3Cp%3Etest3%3C%2Fp%3E%0D%0A"

控制器代码:

 public JsonResult Save(int id, string title, string shortText, string text, DateTime? startDate, DateTime? endDate, string cultureCode)
        {
       //process some operation
}

会抛出一些ajax错误,如" 500 -internal server not found"。我不知道这个问题的真正原因是什么

可能是序列化表单时的问题所在。有什么帮助吗?

我怀疑标签是这里的问题-

假设这里是Asp.net MVC,你有两个选项-

用[AllowHtml]方法修饰你的模型属性(不知道在这里把你的属性转换成模型会有多痛苦)

将[ValidateInput(false)]标签放在控制器方法上您可能需要向系统添加以下标记。Web也在你的配置

<httpRuntime requestValidationMode="2.0"/>

如果你提交的不是一个帖子,你可能也会遇到问题,在这种情况下,你需要在你的返回值中添加allowget。

不确定这是否是您的问题没有完整的错误,但这就是我开始的地方。您可能需要检查fiddler或firebug中的响应,以查看是否可以获得有关该异常的更多信息。

希望有帮助。