weixin_33698043 2017-08-19 17:08 采纳率: 0%
浏览 97

Ajax呼叫错误500

So I am developing a website where users can write articles. I'm coming across a problem. When a user writes a short article it works fine, but when a user writes or edits a longer article it gives me an Ajax 500 Error in the console. I'm not sure if the problem is happening because I'm working with CKEditor. Anyways this is the code I'm using to send my article with Ajax:

var name        = $(".article_name").val().trim(),
    image       = $("#article_input").val(),
    category_id = $(".txtArticleCategory").val().trim(),
    short_body  = $(".txtShortBodyArticle").val().trim(),
    tags        = $(".txtTagsArticle").val().trim(),
    body        = CKEDITOR.instances['txtArticleBody'].getData();

    if(name !== "" && image !== "" && category_id > 0 && body !== "" && short_body !== "" && tags !== ""){    
      var formData = new FormData($('#insertArticleForm')[0]);
      formData.append("body", body);

      $.ajax({
          xhr: function() {
            var xhr = new window.XMLHttpRequest();

            xhr.upload.addEventListener("progress", function(evt) {
              if (evt.lengthComputable) {
                var percentComplete = evt.loaded / evt.total;
                percentComplete = parseInt(percentComplete * 100);

                //update progress bar width
                $('.progress-bar-custom > span').css('width', percentComplete + "%");    
              }
            }, false);

            return xhr;
          },
          type: "POST",
          url: '/actions/update_article.php',
          data: formData,
          processData: false,
          contentType: false,
          success: function (data) {
              $('.progress-bar-custom').css('display', 'none');
              $('.progress-bar-custom > span').css('width', '0%');

              if(data == 'true'){
                // Empty textboxes
                $(".article_name, .txtArticleCategory").val("");
                CKEDITOR.instances['txtArticleBody'].setData("");

                alert('Article added.');
              }else if (data == "size") {
                alert('Image too big. Max size is 2mb');
              }else if (data == "false") {
                alert('Error, please try again.');
              }
          },
          error: function(){
            alert('Error, please try again.');
          }
      });
    }else{
      alert("Complete a text fields.");
    }
  });

This is the error i'm getting:

jquery.min.js:4 POST http://sub.domain.net/actions/update_article.php 500 (Internal Server Error)

The error only happens when I try adding or editing a large article, anyone know why this is happening or how I can fix it? Any help is appreciated.

  • 写回答

1条回答 默认 最新

  • weixin_33725239 2017-08-20 14:03
    关注

    I contacted my web hosting provider and they told me it ended up being a ModSec rule. If you're having a similar issue I would recommend contacting them.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog