GetmeUK / ContentTools

A JS library for building WYSIWYG editors for HTML content.
http://getcontenttools.com
MIT License
3.95k stars 395 forks source link

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data #414

Closed kallekanin closed 7 years ago

kallekanin commented 7 years ago

I get the error: "SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data"

When i click "Upload" button, after selecting a image.

Does anyone know what might be wrong?

anthonyjb commented 7 years ago

@kallekanin the image uploader is expecting a JSON payload back - my guess is you're not returning that from your server side script.

kallekanin commented 7 years ago

I run this: console.log(file); and that gives me a JSON, but that JSON is not valid (tested in JSONLint).

My browser point out this line for the error: response = JSON.parse(ev.target.responseText);

anthonyjb commented 7 years ago

Hi @kallekanin, CT's ImageUploader example class doesn't itself attempt to create and parse JSON, it only parses JSON that is returned to it from a call to the server. I'm not sure what console.log(file) is in reference to here?

kallekanin commented 7 years ago

file uploaded to server, but i still get: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data.

kallekanin commented 7 years ago

Seams like the JSON format from the callback is formated wrong, even tho the file is uploaded to the server, it wount return valid JSON.

Select image -> upload to server -> error -> image is not visible in the frame.

anthonyjb commented 7 years ago

@kallekanin if the server isn't returning valid JSON then that needs to be resolved but that's beyond the scope of CT. I'll happily take a look at your server code if you post it and see if I can spot the issue but keep in mind I don't know what language or framework your using so I might be of limited help.

kallekanin commented 7 years ago

The image are uploaded but it wont show in the editing window (added screenshot)

JS code that trigger uploadscript:

$.getJSON('save.php', 'test', function(e){
    console.log(e);
});

save.php:

<?php
    move_uploaded_file($_FILES['image']['tmp_name'],"images/".$_FILES['image']['name']);
?>

screenshot_1

Gives me this message in browser: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data ( editor.js:128:28 )