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.

    评论

    报告相同问题?

    悬赏问题

    • ¥20 求各位能用我能理解的话回答超级简单的一些问题
    • ¥15 yolov5双目识别输出坐标代码报错
    • ¥15 这个代码有什么语法错误
    • ¥15 给予STM32按键中断与串口通信
    • ¥15 使用QT实现can通信
    • ¥15 关于sp验证的一些东西,求告知如何解决,
    • ¥35 关于#javascript#的问题:但是我写的只能接码数字和字符,帮我写一个解码JS问题
    • ¥15 prophet运行报错,如何解决?
    • ¥15 用GPU跑pytorch搭建的LSTM的时候出现了奇怪的报错
    • ¥20 前端数据是从session等作用域拿到的,如何取值继续传递后端呢