ajaxfileupload上传文件和报错syntaxerror: Unexpected end of input(…)

简介: ajaxfileupload上传文件和报错syntaxerror: Unexpected end of input(…)

jQuery插件AjaxFileUpload可以实现ajax文件上传,下载地址:http://www.phpletter.com/contents/ajaxfileupload/ajaxfileupload.js

主要参数说明:

1,url表示处理文件上传操作的文件路径,可以测试URL是否能在浏览器中直接访问,如上:upload.php

2,fileElementId表示文件域ID,如上:fileToUpload

3,secureuri是否启用安全提交,默认为false

4,dataType数据数据,一般选json,javascript的原生态

5,success提交成功后处理函数

6,error提交失败处理函数

需要了解相关的错误提示

1,SyntaxError: missing ; before statement错误

如果出现这个错误就需要检查url路径是否可以访问

2,SyntaxError: syntax error错误

如果出现这个错误就需要检查处理提交操作的PHP文件是否存在语法错误

3,SyntaxError: invalid property id错误

如果出现这个错误就需要检查属性ID是否存在

4,SyntaxError: missing } in XML expression错误

如果出现这个错误就需要检查文件域名称是否一致或不存在

5,其它自定义错误

大家可使用变量$error直接打印的方法检查各参数是否正确,比起上面这些无效的错误提示还是方便很多。

示例代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type"content="text/html; charset=utf-8"/>

<title>ajaxfileupload图片上传控件</title>

</head>

<script type="text/javascript"src="http://code.jquery.com/jquery-1.6.3.min.js"></script>

<script type="text/javascript"src="http://www.phpletter.com/contents/ajaxfileupload/ajaxfileupload.js"></script>

<script language="javascript">

  jQuery(function(){   

      $("#buttonUpload").click(function(){     

         //加载图标   

         /* $("#loading").ajaxStart(function(){

            $(this).show();

         }).ajaxComplete(function(){

            $(this).hide();

         });*/

          //上传文件

        $.ajaxFileUpload({

            url:'upload.php',//处理图片脚本

            secureuri :false,

            fileElementId :'fileToUpload',//file控件id

            dataType : 'json',

            success : function(data, status){

                if(typeof(data.error) != 'undefined'){

                    if(data.error != ''){

                        alert(data.error);

                    }else{

                        alert(data.msg);

                    }

                }

            },

            error: function(data, status, e){

                alert(e);

            }

    })

    returnfalse;

      }) 

  })

 

</script>

 

 

<body>

<input id="fileToUpload"type="file"size="20"name="fileToUpload"class="input">

<button id="buttonUpload">上传</button>

<!--<img id="loading"src="loading.jpg"style="display:none;">-->

</body>

</html>

后台代码就不贴出来了,按照平常文件上传,取$_FILES数据就行

下面是一个碰到的重点问题!

请注意:ajaxfileupload的ajax,在浏览器可能显示不出来的(本人这边显示不出,其他不清楚)

所以,当出错时,你会一直以为出错在前端!!!

报错为  syntaxerror: Unexpected end of input(…)


image.png

如果发现这个错误!请去后台查找问题,该输出的输出,不能不输出内容,内容要为json数据!

目录
相关文章
|
4月前
TypeError:Joi.validate is not a function 解决办法
TypeError:Joi.validate is not a function 解决办法
|
3月前
|
JSON 缓存 前端开发
Unexpected end of JSON input while parsing near '....1","eslint-loader":"'
Unexpected end of JSON input while parsing near '....1","eslint-loader":"'
|
3月前
|
Python
完美解决丨File “invalid.py“, line 1 print(`Hello World!`) ^ SyntaxError: invalid syntax
完美解决丨File “invalid.py“, line 1 print(`Hello World!`) ^ SyntaxError: invalid syntax
|
4月前
Excel上传出错:TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string or an instan
Excel上传出错:TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string or an instan
|
9月前
error C2449: found ‘{‘ at file scope (missing function header?)和error C2059: syntax error : ‘}‘
error C2449: found ‘{‘ at file scope (missing function header?)和error C2059: syntax error : ‘}‘
72 0
|
9月前
浏览器报错:Uncaught TypeError: Cannot read property ‘trim‘ of undefined
浏览器报错:Uncaught TypeError: Cannot read property ‘trim‘ of undefined
146 0
|
JSON 数据格式
解决报错信息之:SyntaxError: Unexpected token R in JSON at position 0
解决报错信息之:SyntaxError: Unexpected token R in JSON at position 0
304 0
|
JSON 前端开发 JavaScript
SyntaxError: Unexpected number in JSON at position 7 at JSON.parse (<anonymous>)前端接收到数据,无法进入success
SyntaxError: Unexpected number in JSON at position 7 at JSON.parse (<anonymous>)前端接收到数据,无法进入success
160 0
SyntaxError: Unexpected number in JSON at position 7 at JSON.parse (<anonymous>)前端接收到数据,无法进入success
|
JSON 数据格式
报错:应用json.parseObject()方法时JSONException: syntax error, expect {, actual [, pos 0
报错:应用json.parseObject()方法时JSONException: syntax error, expect {, actual [, pos 0
731 0
PHPExcel在高版本PHP7中,Writer-&gt;save出现ERR_INVALID_RESPONSE错误的解决方法
PHPExcel在高版本PHP7中,Writer-&gt;save出现ERR_INVALID_RESPONSE错误的解决方法
204 0