最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jquery file uploader blueimp, Unexpected TokenCharacter - Stack Overflow

programmeradmin1浏览0评论

First of all let me tell you that I've already searched for some answers, and while it helped me out a bit, my main problems remain unresolved.

I used the file uploader (Version 9.8.0) @ /

(1st problem)
Everything seems to work fine until I start uploading. After it finishes uploading, it says the following error for each image (instead of the "upload successful" message).

On Google Chrome it says: "SyntaxError: Unexpected token <"
on Mozilla FireF. it says: "SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data"

I searched some solutions but I can't figure out how to apply these solutions. And btw, it adds the image, despite the error.

First of all let me tell you that I've already searched for some answers, and while it helped me out a bit, my main problems remain unresolved.

I used the file uploader (Version 9.8.0) @ http://blueimp.github.io/jQuery-File-Upload/

(1st problem)
Everything seems to work fine until I start uploading. After it finishes uploading, it says the following error for each image (instead of the "upload successful" message).

On Google Chrome it says: "SyntaxError: Unexpected token <"
on Mozilla FireF. it says: "SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data"

I searched some solutions but I can't figure out how to apply these solutions. And btw, it adds the image, despite the error.

Share Improve this question asked Nov 6, 2014 at 22:05 Jeremy23Jeremy23 1571 gold badge2 silver badges10 bronze badges 3
  • Help me please, someone? – Jeremy23 Commented Dec 1, 2014 at 6:20
  • May i know which version you are using php,ruby,node.js............. – Bik Commented Jun 10, 2015 at 5:39
  • Can you please show the response which you getting from the server or share your url. – Mitul Commented Jun 10, 2015 at 9:00
Add a comment  | 

9 Answers 9

Reset to default 11

The method you are calling is throwing an error page with html (starting with < and cannot be parsed in JSON), if you look at the network tab in your browser.

For example in Google Chrome:

  1. Open debugger: F12
  2. Go to network tab
  3. Do the upload
  4. You should see the request that was sent in the Network tab
  5. Click on that error request
  6. That will open a new window with a tab for the response from the server. This response will most likely be some kind of exception message.

I had a similar problem on ASP.Net MVC with a different uploader, when one of the parameters was sent as null and it wasn't nullable on the controller.

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data check out this SO and see if your problem is related.
Basically, it could mean that the Success Message returned doesn't have proper HTML markup and hence the browser is not able to display them.

Most likely you're trying to JSON.parse a server provided error message or other non-JSON response, and this is probably HTML, given the first character it choked on.

I'd open the console, get the page to produce the error, find the request in the Network tab of the dev tools, and check the response tab of the upload request(s) to see what is actually being returned.

Hopefully seeing the response will lead you to the solution (like fixing an error message) or a more specific question that can be asked.

I solved this problem by editing url in main.js file with index.php at finally, like this:

// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
    // Uncomment the following to send cross-domain cookies:
    //xhrFields: {withCredentials: true},
    url: 'imagegallery/server/php/index.php'
});

This happened to me once. Maybe it is the folder permission. I set the server/php/files permission to read and write and it works.

It is because of the post_max_size and upload_max_filesize are too small and since it uses a blob to send the file data it generates this error. I've increased them in my php.ini and now works like a charm

This happened to me as well. I'm using PHP on a Linux server. I found there were actually backslashes "\" in the code in 4 or 5 places and they were causing the errors. Do this:

  1. Open your copy of /server/php/UploadHandler.php in an editor
  2. Do a search for the backslash: \
  3. Note each location of the backslash.
  4. If it is after the word "new" and before a call to a handler you can remove the backslash.

Check on lines 308, 790, 814, 816, 819, 822, 825, 828, 831, 836, 842, 895, 915, 973, 981 and 1058. All the calls to Imagick(); seem to have one in front of them.

I deleted all those backslashes and was not required to turn off error reporting.

Example:

Find code:

$file = new \stdClass();

Replace with:

$file = new stdClass();

Here is the best answer, I had the same problem but following these steps, I could see the error easily.

1- Open debugger: F12

2- Go to network tab

3- Do the upload

4- You should see the request that was sent in the Network tab

5- Click on that error request

6- That will open a new window with a tab for the response from the server. This response will most likely be some kind of exception message.

Thanks StephanC

I had this problem in php 5.6 but not in php 5.3. I "solved" this problem by editing the error reporting level in upload.php file :

//error_reporting(E_ALL | E_STRICT); error_reporting(E_STRICT);

发布评论

评论列表(0)

  1. 暂无评论