小编mob*_*bro的帖子

语法错误:输入parseJSON的意外结束

我大约在第5个小时,并认为是时候寻求帮助了.我正在尝试使用AJAX + php将表单上的图像和一些文本数据上传到数据库.整个系统是:

一个带有表单的输入页面,social.php 一个php处理页面postMsg.php 和一个javascript函数postMsg(),它将表单发布到php处理页面,并且应该将结果返回给divsocial.php

问题是javascript中的$ .parseJSON(data)命令导致"意外的输入结束"错误:

Failed:  
SyntaxError {stack: (...), message: "Unexpected end of input"}
(index):156
Uncaught SyntaxError: Unexpected end of input jquery.js:4235
b.extend.parseJSON jquery.js:4235
(anonymous function) (index):158
c jquery.js:4611
p.fireWith jquery.js:4687
k jquery.js:10335
r
Run Code Online (Sandbox Code Playgroud)

我以为我的javascript存在问题,但我对其进行了代码检查,并且没关系:

     function postMsg() {
        console.log("submit event");
        var fd = new FormData(document.getElementById("commentSubmit"));
        fd.append("label", "WEBUPLOAD");
        document.getElementById('progressBar').style.display = 'block';

        $.ajax({
          url: "postMsg.php",
          type: "POST",
          xhr: function() {  // Custom XMLHttpRequest
            var myXhr = $.ajaxSettings.xhr();
            if(myXhr.upload){ // Check if upload property exists …
Run Code Online (Sandbox Code Playgroud)

html javascript php ajax jquery

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

ajax ×1

html ×1

javascript ×1

jquery ×1

php ×1