I donβt know why, but there is a problem that I encounter $.parseJSON when making an ajax call, I need to check if the response contains JSON and then continue parsing with $.parseJSON if it does not contain JSON, then it will print the response in the element (which the response will contain some HTML).
Then I tested if eval would do something, which of course happened, but I don't want to use eval to do this.
The code I have is:
$.ajax({ url: 'ajax.php', success: function(response) { var msg = $.parseJSON(response);
So why couldn't he parse the JSON string? jQuery.parseJSON clearly says:
Generates a valid JSON string and returns the resulting JavaScript object.
But nothing can be analyzed, is it some kind of mistake or maybe a mistake?
EDIT: JSON:
[{"error":"Error loading template"}]
json jquery parsing
Macmac
source share