I know this question has been asked many times but I can't find similarity with my issue. I'm getting this error only in Chrome, in every other browser everything is ok. I return data with JSON in several places but since my code works in other browsers I assume nothing is wrong with it. Chrome doesn't show me where is error (in my code) it shows me these errors:
This is how I use JSON:
$.post("getData.php", {'id' : id}, function(data){
var obj = jQuery.parseJSON(data);
.
.
.
... some mysqli query
$data = $query->fetch_assoc();
echo json_encode($data);
So I don't see a problem here, can someone help me with this.
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. This might be a simple typo.
To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type of your <script /> tags to module , e.g. <script type="module" src="index. js"></script> . The type="module" attribute is supported in all modern browsers and allows us to use the ES6 modules syntax. Copied!
To solve the "Uncaught SyntaxError: Unexpected identifier" error, make sure you don't have any misspelled keywords, e.g. Let or Function instead of let and function , and correct any typos related to a missing or an extra comma, colon, parenthesis, quote or bracket.
You can check your Network (console) and See the answer from the Server ... The "<" will be the first letter of your response. Something like "<"undefined index XY in line Z>"
My solution to this is pretty unbelievable.
<script type="text/javascript" src="/js/dataLayer.js?v=1"></script>
The filename in the src attribute needed to be lowercase:
<script type="text/javascript" src="/js/datalayer.js?v=1"></script>
and that somewhat inexplicably fixed the problem.
In both cases the reference was returning 404 for testing.
Error with Uncaught SyntaxError: Unexpected token <
using @Mario answer but that was only part of my problem. Another problem is, javascript doesn't get any data from PHP file. That was solved using this code, inside PHP file: header("Content-Type: text/javascript; charset=utf-8");
This answer is found on this link, where I opened another question to solve this issue: Can't receive json data from PHP in Chrome and Opera
I got the same error ("Uncaught SyntaxError: Unexpected token <" ) at these two lines when testing a sample application .
<script type = "text/javascript" src="raphael-min.js"></script>
<script type = "text/javascript" src="kuma-gauge.jquery.js"></script>
After a control, I realized that, local file locations are not correct and my local server app returns default page as the result. Client app can find the files but the founded files are default page, not the *.js files. So I receive Uncaught SyntaxError: Unexpected token <
I changed to orginal location on the intenet andit solved.
<script type = "text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.2/raphael-min.js"></script>
<script type = "text/javascript" src="//www.jqueryscript.net/demo/Creating-Animated-Gauges-Using-jQuery-Raphael-js-kumaGauge/js/kuma-gauge.jquery.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With