Uncaught SyntaxError: Unexpected token ILLEGAL Jquery - javascript

I know there are a lot of questions on this issue. But I want to know if there are any alternatives to solve this issue.
PROBLEM:
I want to fetch existing text in database tables and put it in Textarea in HTML. I am using Django framework.
$("textarea[name=profileitemdescription]").val("{{item.item_description}}");
the above code works when there are no line breaks \n in {{item.item_description}}.
It puts value in Textarea if the value({{item.item_description}}) is a single line. Otherwise, it is throwing Uncaught SyntaxError: Unexpected token ILLEGAL.
Any workaround to put value({{item.item_description}}) in Textarea ?

Related

Getting "Uncaught SyntaxError: Unexpected token '<'" in all of our site pages as Javascript Error in Google Console

This seems to come up as an issue occasionally but I can't find a solution or reference that matches our issue.
Google Developer Console is reporting this as a red X error on every page on our site, would love some help figuring out what is causing it and where/how to eliminate it. Is there a problem with the jquery.min.js 3.51 that is being called?
Here is the readout of the console error in every page on our site.
Uncaught SyntaxError: Unexpected token '<'
at b (jquery.min.js?ver=3.5.1:formatted:48)
at Function.globalEval (jquery.min.js?ver=3.5.1:formatted:152)
at text script (jquery.min.js?ver=3.5.1:formatted:3940)
at jquery.min.js?ver=3.5.1:formatted:3750
at l (jquery.min.js?ver=3.5.1:formatted:3762)
at XMLHttpRequest.<anonymous> (jquery.min.js?ver=3.5.1:formatted:3899)
If I need to provide more details please let me know what would help troubleshoot this.
screenshot
Thank you!
Looks like you'd be missing something like a }, ], etc. Hard to tell without code. But that's usually what the error is when you get a syntax error. It's going to be in your code because jquery is tested.

(index):889 Uncaught SyntaxError: Unexpected token <

I'm using Google Analyticator and my website is http://gestionalemagazzinoonline.it/
You can see the error in the javascript console.
I think that is the suspected file:
https://github.com/wp-plugins/google-analyticator/blob/master/google-analyticator.php
The problem is also if i disable the plugin, or if i change the source code i don't see the changes (maybe there's a cache?).
How can I fix?
Script tags are meant to write javascript in them, and not html.
You have a script block inside a script block. Remove that, and it will work all fine.

Uncaught SyntaxError: Unexpected token \

I have a stringified JSON-Object inside another JSON-Object. I get it via $.ajax() from my database like this:
data => {"foo":"[{\"foo\":\"bar\"},{\"foo2\":\"bar2\"}]"}
When trying to do JSON.parse(data.foo), I get an Uncaught SyntaxError: Unexpected token \.
What am I doing wrong? (Apart from the fact, that the object needs to be saved as a string.)
You have to escape html tags. Which language are you using in back end? In python Django it is done by using the safe filter. Similar might exist in php or other languages.
Thank you for your help. It seems, the data coming from the database "looked" right, but wasn't. I assume this was because I put the data in the database by hand.
Now I put the data via my API with JSON.stringify() and now everythings looks fine.

JavaScript eval - "SyntaxError: Unexpected token ILLEGAL"

eval("Encryption={Load:function(enc){var id=enc.split('/z');var e=[id[0],id[2]];id=toNumber(string.reverse(id[1]));enc=e.join('');e=enc.substring(1).split('/');var fin='';console.log(id);for(var CN=0;CN<e.length;CN++){fin+=string.char(toNumber(e[CN])/id);}eval(fin);}};");
It's all on one line because adding new lines into the string (even if I just put \n), causes another error.
When I run this, I get the error, "Uncaught SyntaxError: Unexpected token ILLEGAL"
I can't understand why. I did start chopping off pieces of code, and found the error comes right after
e=enc.substring(1).split('/');
is added.
So if I remove everything in Encryption's Load function including that, it will work.
Though I need all of the function.
And I did Google it, and nothing seemed to fit what I was looking for.
You had an invalid character in the initial code you posted which you have fixed in your edit:
This works fine:
eval("Encryption={Load:function(enc){var id=enc.split('/z');var e=[id[0],id[2]];id=toNumber(string.reverse(id[1]));enc=e.join('');e=enc.substring(1).split('/');var fin='';console.log(id);for(var CN=0;CN<e.length;CN++){fin+=string.char(toNumber(e[CN])/id);}eval(fin);}};");
as it can be seen from this this jsfiddle.

how to narrow down dojo 1.4 javascript error : Uncaught SyntaxError: Unexpected token ILLEGAL

I got a javascript error "Uncaught SyntaxError: Unexpected token ILLEGAL" in chrome's debugger while loading a page. we're using a customised version of dojo 1.4.x
n.text = code;
I noticed that the variable "code" had a huge amount of application code. Somewhere inside, it appears is the javascript syntax error. Since the code is huge, I don't know where exactly the problem is coming up. How do I go about narrowing down where the the problem is ?
Use the debugger to get the value of the code variable, and copy it to the clipboard.
Paste it into a blank HTML document, or an empty JSFiddle, and run it with the console visible. That will show you where the syntax error is.
(Even if there are missing dependencies etc., a syntax error ought to show up.)

Categories