sconsult / croppic

croppic
915 stars 229 forks source link

Uncaught SyntaxError: Unexpected token i #196

Closed bologer closed 8 years ago

bologer commented 8 years ago

Receive this error when image is being cropped.

  1. Image uploads correctly via img_save_to_file.php. - OK, image saves in the folder that I specified.
  2. After I chose size of the image in the prepared container, I try to crop it, however when I crop it, every time I get this error message in the console: Uncaught SyntaxError: Unexpected token i - and of course image does not appear in the folder.

PS. I use the latest version of all files of the plugin.

Please help.

Thank in advance.

charlesaraujo commented 8 years ago

i have the same trouble

erhankaradeniz commented 8 years ago

I had the same problem, took me some time to figure it out. It's not clearly documented on the website, but what you need to do is, asuming that you use the php files provided by the creator:

You need to create the options:

var croppicHeaderOptions = {
uploadUrl:'img_save_to_file.php',
cropUrl:'img_crop_to_file.php'
}

The uploadUrl is for the upload functionality where you select your file and the image is displayed in the 'cropbox'. The cropUrl option is used for after you have cropped the image a new image is created and saved on your server.

If one of these urls is not set, you will not be able to upload or crop the image.

Hope this helped, took me some time to figure it out, but when I looked at the response I got back, it was just posting back to the page itself (so I received HTML) where the script expects a JSON response so it triggers this error.

erhankaradeniz commented 8 years ago

I forgot to mention. You can also use the processInline:true option. This way you can ommit the option uploadUrl:'img_save_to_file.php', Because image processing will be done on the client side.

But you still need the option cropUrl:'img_crop_to_file.php' for actually saving the cropped image.

bologer commented 8 years ago

@erhankaradeniz thank you, I will try it today and tell you the result of it. Was waiting for someone who could explain it to me. Because could not figure it out "why it is not working?" For me it seemed that I was doing everything correct. The most annoying thing is that on the demo of the plugin everything works like a charm.

Have you manage to use this plugin?

erhankaradeniz commented 8 years ago

@bologer Alright, I think it will work for you now after making the changes I have written. As I was stuck on the same problem.

After those changes I've written above the plugin works like a charm! No more errors, just need to rewrite the php files so everything is handled with imageMagic.

bologer commented 8 years ago

@erhankaradeniz tried to apply your changes now. It worked, as it did not show the error message in the console and now it does not show any messages - which is good.

Problem now is the following: without processInline: true file img_save_to_file.php does not upload file on the server as well as, cropping is no happening. No error shown as well. Also, after I click crop image, it returns the same state, such as "allows to choose another image and do the process over and over".

When I remove processInline: true I get the same error as was in my first entry. And no cropping is allow, however image is uploaded successfully.

Do you know what can be the problem?

erhankaradeniz commented 8 years ago

Can you share you Javascript code? When you use processInline, you do NOT need the uploadUrl:'img_save_to_file.php', but you should use 'cropUrl:'img_crop_to_file.php'' instead.

bologer commented 8 years ago

@erhankaradeniz This is JS:

    var croppicOptions = {
        // uploadUrl:'/img_save_to_file.php',
        cropUrl:'/img_crop_to_file.php',
        processInline: true
    }

    var cropperHeader = new Croppic('change-full-image', croppicOptions);

according to what you have said in the last reply

erhankaradeniz commented 8 years ago

It looks like that should work. I don't see anything wrong there.

You said before that the previous changes worked, does that mean that the cropped image was saved successful? Why do you want to have the image processed inline?

bologer commented 8 years ago

@erhankaradeniz I want either:

  1. image to be uploaded on the server, displayed in the container, cropped and saved back on the server;
  2. image to be displayed in the container, cropped and then uploaded on the server.

Basically, the problem is just with cropping.

erhankaradeniz commented 8 years ago

then I would just do this:

var croppicHeaderOptions = {
uploadUrl:'img_save_to_file.php',
cropUrl:'img_crop_to_file.php'
}

That should work. That's currently the config I'm using which works fine. If this doesnt work (if no image is uploaded, check in in your php files if the folders are correct. and have read/write permission.

bologer commented 8 years ago

If I just do this, I receive this error Uncaught SyntaxError: Unexpected token i

var croppicHeaderOptions = {
uploadUrl:'img_save_to_file.php',
cropUrl:'img_crop_to_file.php'
}

Have no ideas what is wrong with it.

erhankaradeniz commented 8 years ago

Are you using the minified version? I also use the non-minified version for development.

Verstuurd vanaf mijn iPhone

Op 30 jan. 2016 om 16:11 heeft Alexander Teshabaev notifications@github.com het volgende geschreven:

If I just do this, I receive this error Uncaught SyntaxError: Unexpected token i

var croppicHeaderOptions = { uploadUrl:'img_save_to_file.php', cropUrl:'img_crop_to_file.php' } Have no ideas what is wrong with it.

— Reply to this email directly or view it on GitHub.

bologer commented 8 years ago

@erhankaradeniz minified

erhankaradeniz commented 8 years ago

Can you try the not minified version? If you receive the same error, but the token is '<' then I think it's not calling the php file.

Verstuurd vanaf mijn iPhone

Op 30 jan. 2016 om 16:16 heeft Alexander Teshabaev notifications@github.com het volgende geschreven:

@erhankaradeniz minified

— Reply to this email directly or view it on GitHub.

bologer commented 8 years ago

@erhankaradeniz tried what you said, however still have the same issue (Uncaught SyntaxError: Unexpected token i).

bologer commented 8 years ago

@erhankaradeniz all worked. problem was with paths in file img_crop_to_file.php (I used different path for saving images).