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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀