Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  16] [ 5]  / answers: 1 / hits: 35143  / 11 Years ago, wed, november 6, 2013, 12:00:00

I have a JSON parse error that I can't debug. Code below:



$(document).on('submit', '#confirmreset', function(event) {
event.preventDefault();

var action_url = $(this).attr(action);
alert_box_register(Resetting password...);
console.log(action_url);
var postData = $(this).serializeArray();
console.log(postData);

$.post(action_url, postData, function(data) {
console.log(data);
var obj = $.parseJSON(data);

alert_box_register(obj.message);
});
});


And the JSON:



{
status: success,
message: A temporary password has been emailed to you.
}


In Firefox the error is SyntaxError: JSON.parse: unexpected character, in Chrome it's Uncaught SyntaxError: Unexpected token C



Any ideas?



*EDIT: This works fine on my localhost setup. *


More From » jquery

 Answers
17

You don't need to call $.parseJSON if the server is sending valid JSON as jQuery will parse it automatically when it retrieves the response. I don't know the exact criteria, but if you set the Content-type: application/json header it definitely will.


[#74454] Wednesday, November 6, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pranavrorys

Total Points: 466
Total Questions: 87
Total Answers: 115

Location: Barbados
Member since Sun, Nov 27, 2022
2 Years ago
pranavrorys questions
Fri, May 27, 22, 00:00, 2 Years ago
Thu, Oct 28, 21, 00:00, 3 Years ago
Sat, May 30, 20, 00:00, 4 Years ago
Fri, Dec 20, 19, 00:00, 5 Years ago
;