VM2022:2 Uncaught SyntaxError: Unexpected token : on AJAX call
I send a GET request from the back end to get the json response. I got this error.
Uncaught SyntaxError: Unexpected token :
at DOMEval (jquery-3.3.1.js:111)
at Function.globalEval (jquery-3.3.1.js:345)
at text script (jquery-3.3.1.js:9640)
at ajaxConvert (jquery-3.3.1.js:8787)
at done (jquery-3.3.1.js:9255)
at XMLHttpRequest. (jquery-3.3.1.js:9548)
My AJAX request code is:
$.ajax(
type: "GET", //rest Type
dataType: 'jsonp', //mispelled
url: " url_for('live') ",
contentType: "application/json",
success: function (msg)
console.log(msg);
for (var i = 0; i < msg.counters.length; i++)
var counter = msg.counters[i];
console.log(counter);
,
error: ErrorMsg
);
I have no idea where I went wrong. please help.
javascript python jquery json ajax
|
show 2 more comments
I send a GET request from the back end to get the json response. I got this error.
Uncaught SyntaxError: Unexpected token :
at DOMEval (jquery-3.3.1.js:111)
at Function.globalEval (jquery-3.3.1.js:345)
at text script (jquery-3.3.1.js:9640)
at ajaxConvert (jquery-3.3.1.js:8787)
at done (jquery-3.3.1.js:9255)
at XMLHttpRequest. (jquery-3.3.1.js:9548)
My AJAX request code is:
$.ajax(
type: "GET", //rest Type
dataType: 'jsonp', //mispelled
url: " url_for('live') ",
contentType: "application/json",
success: function (msg)
console.log(msg);
for (var i = 0; i < msg.counters.length; i++)
var counter = msg.counters[i];
console.log(counter);
,
error: ErrorMsg
);
I have no idea where I went wrong. please help.
javascript python jquery json ajax
msg
is already an object so decoding it again will cause the error you see. You just need to remove thevar msg = JSON.decode(msg);
line
– Rory McCrossan
Nov 13 '18 at 10:59
@RoryMcCrossan still getting the error
– Balakrishnan Sathiyakugan
Nov 13 '18 at 11:05
Is it the same error?
– Rory McCrossan
Nov 13 '18 at 11:05
@RoryMcCrossan yes same error. VM2335:2 Uncaught SyntaxError: Unexpected token :
– Balakrishnan Sathiyakugan
Nov 13 '18 at 11:10
1
Glad you got it working. I added an answer for you below.
– Rory McCrossan
Nov 13 '18 at 11:17
|
show 2 more comments
I send a GET request from the back end to get the json response. I got this error.
Uncaught SyntaxError: Unexpected token :
at DOMEval (jquery-3.3.1.js:111)
at Function.globalEval (jquery-3.3.1.js:345)
at text script (jquery-3.3.1.js:9640)
at ajaxConvert (jquery-3.3.1.js:8787)
at done (jquery-3.3.1.js:9255)
at XMLHttpRequest. (jquery-3.3.1.js:9548)
My AJAX request code is:
$.ajax(
type: "GET", //rest Type
dataType: 'jsonp', //mispelled
url: " url_for('live') ",
contentType: "application/json",
success: function (msg)
console.log(msg);
for (var i = 0; i < msg.counters.length; i++)
var counter = msg.counters[i];
console.log(counter);
,
error: ErrorMsg
);
I have no idea where I went wrong. please help.
javascript python jquery json ajax
I send a GET request from the back end to get the json response. I got this error.
Uncaught SyntaxError: Unexpected token :
at DOMEval (jquery-3.3.1.js:111)
at Function.globalEval (jquery-3.3.1.js:345)
at text script (jquery-3.3.1.js:9640)
at ajaxConvert (jquery-3.3.1.js:8787)
at done (jquery-3.3.1.js:9255)
at XMLHttpRequest. (jquery-3.3.1.js:9548)
My AJAX request code is:
$.ajax(
type: "GET", //rest Type
dataType: 'jsonp', //mispelled
url: " url_for('live') ",
contentType: "application/json",
success: function (msg)
console.log(msg);
for (var i = 0; i < msg.counters.length; i++)
var counter = msg.counters[i];
console.log(counter);
,
error: ErrorMsg
);
I have no idea where I went wrong. please help.
javascript python jquery json ajax
javascript python jquery json ajax
edited Nov 13 '18 at 11:05
Balakrishnan Sathiyakugan
asked Nov 13 '18 at 10:58
Balakrishnan SathiyakuganBalakrishnan Sathiyakugan
587
587
msg
is already an object so decoding it again will cause the error you see. You just need to remove thevar msg = JSON.decode(msg);
line
– Rory McCrossan
Nov 13 '18 at 10:59
@RoryMcCrossan still getting the error
– Balakrishnan Sathiyakugan
Nov 13 '18 at 11:05
Is it the same error?
– Rory McCrossan
Nov 13 '18 at 11:05
@RoryMcCrossan yes same error. VM2335:2 Uncaught SyntaxError: Unexpected token :
– Balakrishnan Sathiyakugan
Nov 13 '18 at 11:10
1
Glad you got it working. I added an answer for you below.
– Rory McCrossan
Nov 13 '18 at 11:17
|
show 2 more comments
msg
is already an object so decoding it again will cause the error you see. You just need to remove thevar msg = JSON.decode(msg);
line
– Rory McCrossan
Nov 13 '18 at 10:59
@RoryMcCrossan still getting the error
– Balakrishnan Sathiyakugan
Nov 13 '18 at 11:05
Is it the same error?
– Rory McCrossan
Nov 13 '18 at 11:05
@RoryMcCrossan yes same error. VM2335:2 Uncaught SyntaxError: Unexpected token :
– Balakrishnan Sathiyakugan
Nov 13 '18 at 11:10
1
Glad you got it working. I added an answer for you below.
– Rory McCrossan
Nov 13 '18 at 11:17
msg
is already an object so decoding it again will cause the error you see. You just need to remove the var msg = JSON.decode(msg);
line– Rory McCrossan
Nov 13 '18 at 10:59
msg
is already an object so decoding it again will cause the error you see. You just need to remove the var msg = JSON.decode(msg);
line– Rory McCrossan
Nov 13 '18 at 10:59
@RoryMcCrossan still getting the error
– Balakrishnan Sathiyakugan
Nov 13 '18 at 11:05
@RoryMcCrossan still getting the error
– Balakrishnan Sathiyakugan
Nov 13 '18 at 11:05
Is it the same error?
– Rory McCrossan
Nov 13 '18 at 11:05
Is it the same error?
– Rory McCrossan
Nov 13 '18 at 11:05
@RoryMcCrossan yes same error. VM2335:2 Uncaught SyntaxError: Unexpected token :
– Balakrishnan Sathiyakugan
Nov 13 '18 at 11:10
@RoryMcCrossan yes same error. VM2335:2 Uncaught SyntaxError: Unexpected token :
– Balakrishnan Sathiyakugan
Nov 13 '18 at 11:10
1
1
Glad you got it working. I added an answer for you below.
– Rory McCrossan
Nov 13 '18 at 11:17
Glad you got it working. I added an answer for you below.
– Rory McCrossan
Nov 13 '18 at 11:17
|
show 2 more comments
1 Answer
1
active
oldest
votes
You have two issues. Firstly the response will already be deserialised for you buy jQuery. Deserialising it again will cause the error you see. Secondly, the response format appears to be JSON, not JSONP, so the dataType
property needs to be amended as well. Try this:
$.ajax(
type: "GET",
dataType: 'json',
url: " url_for('live') ",
contentType: "application/json",
success: function (msg)
for (var i = 0; i < msg.counters.length; i++)
var counter = msg.counters[i];
console.log(counter);
,
error: ErrorMsg
);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279510%2fvm20222-uncaught-syntaxerror-unexpected-token-on-ajax-call%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have two issues. Firstly the response will already be deserialised for you buy jQuery. Deserialising it again will cause the error you see. Secondly, the response format appears to be JSON, not JSONP, so the dataType
property needs to be amended as well. Try this:
$.ajax(
type: "GET",
dataType: 'json',
url: " url_for('live') ",
contentType: "application/json",
success: function (msg)
for (var i = 0; i < msg.counters.length; i++)
var counter = msg.counters[i];
console.log(counter);
,
error: ErrorMsg
);
add a comment |
You have two issues. Firstly the response will already be deserialised for you buy jQuery. Deserialising it again will cause the error you see. Secondly, the response format appears to be JSON, not JSONP, so the dataType
property needs to be amended as well. Try this:
$.ajax(
type: "GET",
dataType: 'json',
url: " url_for('live') ",
contentType: "application/json",
success: function (msg)
for (var i = 0; i < msg.counters.length; i++)
var counter = msg.counters[i];
console.log(counter);
,
error: ErrorMsg
);
add a comment |
You have two issues. Firstly the response will already be deserialised for you buy jQuery. Deserialising it again will cause the error you see. Secondly, the response format appears to be JSON, not JSONP, so the dataType
property needs to be amended as well. Try this:
$.ajax(
type: "GET",
dataType: 'json',
url: " url_for('live') ",
contentType: "application/json",
success: function (msg)
for (var i = 0; i < msg.counters.length; i++)
var counter = msg.counters[i];
console.log(counter);
,
error: ErrorMsg
);
You have two issues. Firstly the response will already be deserialised for you buy jQuery. Deserialising it again will cause the error you see. Secondly, the response format appears to be JSON, not JSONP, so the dataType
property needs to be amended as well. Try this:
$.ajax(
type: "GET",
dataType: 'json',
url: " url_for('live') ",
contentType: "application/json",
success: function (msg)
for (var i = 0; i < msg.counters.length; i++)
var counter = msg.counters[i];
console.log(counter);
,
error: ErrorMsg
);
answered Nov 13 '18 at 11:17
Rory McCrossanRory McCrossan
242k29207245
242k29207245
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279510%2fvm20222-uncaught-syntaxerror-unexpected-token-on-ajax-call%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
msg
is already an object so decoding it again will cause the error you see. You just need to remove thevar msg = JSON.decode(msg);
line– Rory McCrossan
Nov 13 '18 at 10:59
@RoryMcCrossan still getting the error
– Balakrishnan Sathiyakugan
Nov 13 '18 at 11:05
Is it the same error?
– Rory McCrossan
Nov 13 '18 at 11:05
@RoryMcCrossan yes same error. VM2335:2 Uncaught SyntaxError: Unexpected token :
– Balakrishnan Sathiyakugan
Nov 13 '18 at 11:10
1
Glad you got it working. I added an answer for you below.
– Rory McCrossan
Nov 13 '18 at 11:17