I get a syntax error after JQuery upgrade from 1.51 to 2 -
the code hasn't changed jquery version. simplified version of ajax call is:
$.ajax( { type: 'get', url: mappath($(this).attr('path')), cache: false, data: '{}', datatype: 'html', success: function (result) { console.log(result); if ($(result).filter('#feedback').length > 0) { $('#center').children(':first').before($(result).filter('#feedback').outerhtml()); } else { $('#feedback').remove(); $('#dialog').html(result); $('#dialog').dialog('option', 'title', 'edit mailbox'); $('#dialog').dialog('open'); } } });
just before if statement log result. shows expected formatted html snippet. snippet meaning contains div child elements. when use selector in if statement error:
throw error("syntax error, unrecognized expression:
i can use console view contents of result , if try selector error. error if use:
$(result)
however if modify result , prepend <html><body>
, append </body></html>
works no error. changed jquery break , how work around it? result needs html snippet setting container on page value.
since can't see html string, can't point out causing not work $()
, fixing should easy using $.parsehtml()
on result
first. if doesn't parse properly, html invalid.
result = $.parsehtml(result); console.log(result); if ($(result).filter('#feedback').length > 0) { $('#center').children(':first').before($(result).filter('#feedback').outerhtml()); } else { $('#feedback').remove(); $('#dialog').html(result); $('#dialog').dialog('option', 'title', 'edit mailbox'); $('#dialog').dialog('open'); }
Comments
Post a Comment