Jquery.html () method doesn't work in chrome and safari

I am trying to display a popup by extracting html data using the GET method and adding to the div using the .html () method. below is the code I wrote for it. This works fine in IE and Firefox, but it doesn't work in Chrome and Safari.

function openPopupWindow(url, width) { $.ajax({ url: url, type: 'GET', timeout: 180000, success: function(data){ var popUpBody = $("div.popupDivClass").html(data); $(popUpBody).dialog({ autoOpen: false, resizable: false, width:width, modal: true }); //$("div.ui-dialog-titlebar").hide(); $(popUpBody).dialog( "open" ); } }); } 

I get the following exception:

Unsuccessful error: INVALID_STATE_ERR: DOM 11 exception - jquery-1.4.4.min.js: 122

Any suggestions?

+4
source share
4 answers

You need to remove any link to DOCTYPE. For instance. I had the same problem and I deleted the following line and it worked like a charm:

 <!doctype html public "*"> 
+5
source

Perhaps this is because you select $("div.popupDivClass") , which can be multiple elements. and html(data) does not know what to return from an array of elements. Try something like this

 $("div.popupDivClass").each(function () { $(this).html(data); }) 

Or try to select id

Note. However not guaranteed.

0
source

The following are two lines. I removed the bottom rows from the data row and worked in chrome and safari mode:

 <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
0
source

Well, just to help other people having issues with Chrome and possibly Safari. Chrome seems to be very skeletal with things that can be inserted using jquery.html ().

I found two cases where Chrome yells Error: INVALID_STATE_ERR: DOM 11 exception

  • When pasting bad html. Like. Upss I forgot to close the tag with /. So $('body').html("<button value='This is a button'>"); going to give you exception 11. The solution to this is easy, just insert valid XHTML.

  • Try this on the chrome console $('body').html("C&aacute;psula"); The problem there is with the ampersand. My (almost) solution for this case converts an ampersand to Unicode, for example $ ('body'). Html ("\ u0026psula"); & Note that the ampersand is not the only character that fights chrome.

Maybe the page encoding has something to do with this.

So your problem is your data variable returning your Ajax

0
source

Source: https://habr.com/ru/post/1344224/


All Articles