0

I've been debugging this for hours already but really can't find the culprit of this illegal character. My javascript looks fine. This is my code.

this.PrintApplication = function Test$PrintApplication(ApplicationID, callback) {
        $.post("/Application/PrintApplication/" + ApplicationID,
        function (data) {
            var result = eval(data);
            if (result.error) {
                DisplayPrompt("Error", result.message);
                return;
            }
            else {
                callback(result.data);
            }
        });
    };

In firebug it shows.

enter image description here

In inspect in chrome and in console it redirects me in this line.

enter image description here

Any idea where is that illegal character is in my function?

7
  • What does data contain, and are you absolutely sure that using eval is necessary? Commented Apr 7, 2016 at 9:38
  • what is there in the data? Commented Apr 7, 2016 at 9:38
  • it only returns true Commented Apr 7, 2016 at 9:39
  • Are you sure? You might want to console.log it before evaling it - the fact that the error message says it's on line 1 would indicate it's the eval of the data that's causing it. Commented Apr 7, 2016 at 9:40
  • 1
    Also, if it only returns true, why are you accessing an error property on it? Commented Apr 7, 2016 at 9:41

3 Answers 3

2

It looks like you've got some unprintable characters in your source. Do you have a way of displaying those in your editor and deleting them? Deleting and retyping the line might fix it as well.

If that's not the case, maybe what you're trying to evaluate isn't JavaScript at all. You could be running that on an image or some kind of binary data.

Remember to be extra super careful when using eval on data that comes from an external source. If you can avoid doing it, avoid it.

Sign up to request clarification or add additional context in comments.

2 Comments

I'll try to look at it and try your suggestion.
You're right bro. The download excel behind my code is messing around my output. And javascript can't read it. Thanks I now have a lead.
1

This might be due to the reason that you have copied the code from web and simply pasted in your file. Try typing the same code to the file.

This error occurs due to UTF-8 characters.

Comments

0

This could happen if you normally type with different alphabets. For example the Γreek question mark ; is a different ASCII character from the English semi colon ;. If you use the first, you'll get exactly this error.

One solution is to copy paste your method to notepad and then back to your IDE. This will often normalise and eliminate weird characters that might be hidden or undecipherable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.