Issue
I cant find anything on the web about this mysterious bug. I wrote a simple Ajax calling a CakePHP Controller-Function to render a simple View. Finally i want to put that rendered HTML into a Popup:
The Ajax:
$.ajax({
url: $('base').attr('href') + '/myController/renderPopupContent/' + this.view,
type: "GET",
dataType: "html",
context: this,
success: function( data ) {
this.content = data;
this.show();
},
error: function(xhr, status) {
showMessage(status, xhr);
}
});
Now i get a jQuery-Error which says:
Uncaught SyntaxError: Unexpected token <
This is because jQuery tries to (automatically^^) parse the response as JSON. If i debug the script it breaks at jQuery (1.9.1) at Line 541 and it really tries to parse that html-response (STRING!) into/from JSON.
How can i avoid this and get jquery known of the dataType "HTML"
Additional Info:
The jQuery-Error (@Ln541) occures after an "alert();" in my success-callback, so the Ajax is already done when the error is thrown.
Solution
Somewhere in another JS-File i found this snippet:
$(document).ajaxSuccess(function(evt, xhr, options) {
var response = $.parseJSON(xhr['responseText']);
This obviously fires after every ajax and tries parsing the response.
Answered By - Jonathan
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.