jQuery AJAX parses HTML response as JSON -
i cant find on web mysterious bug. wrote simple ajax calling cakephp controller-function render simple view. want put rendered html 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 jquery-error says:
uncaught syntaxerror: unexpected token <
this because jquery tries (automatically^^) parse response json. if debug script breaks @ jquery (1.9.1) @ line 541 , tries parse html-response (string!) into/from json.
how can avoid , jquery known of datatype "html"
additional info:
the jquery-error (@ln541) occures after "alert();" in success-callback, ajax done when error thrown.
found issue:
somewhere in js-file found snippet:
$(document).ajaxsuccess(function(evt, xhr, options) { var response = $.parsejson(xhr['responsetext']);
this fires after every ajax , tries parsing response.
Comments
Post a Comment