I have the error Uncaught SyntaxError: Unexpected token ILLEGAL
in Chrome.
The code is
$("form#new_redemption").live('submit', function() {
event.preventDefault();
var that = $(this);
var action = that.attr('action');
var data = that.serialize();
$.ajax({
type: "POST",
url: action,
data: data,
dataType: 'json',
beforeSend: function(request) {
request.setRequestHeader("Accept", "application/json");
},
success: function(res) {
var response = JSON.parse(res.responseText); // <~~~ Unexpected token ILLEGAL
if (response.message) {
that.slideUp();
$("#results").html(response.message).attr('class', 'notice').slideDown();
}
else if (response.url) {
window.location = response.url
}
},
error: function(res) {
var response = JSON.parse(res.responseText);
$('#results').html(response.error).attr('class', 'error').slideDown();
}
});
return false;
});
On errors, this code works great. But every time its a successful response I get an error. Is there a problem here? And is there a way in VIM to highlight illegal javascript characters in the code?
Thank you!