JQuery cannot use ajax response as context in IE

My problem is that in my ajax callback, when I set the context of my request as the returned html of my ajax call, it cannot find any elements.

Some conclusions:

  • The problem never occurs in Firefox
  • The problem only occurs in IE when registering as a user in SharePoint with a certain number of permissions, resulting in some additional html being generated to facilitate administrative functions. I have come to the conclusion that this extra html is the reason for this.

Unfortunately I have no control over the generated html as it is generated by SharePoint.

I isolated the problem and created a simple test page to view.

+2


source to share


3 answers


The problem is the way jQuery runs the html passed in to it, possibly lacking a good cross-browser string-home parsing technique (like createContextualFragment on Mozilla).

To be specific, there are two regular expressions in the jQuery clean function that need to be fixed:

857: var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
874: elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){

      



Both of them will not be able to handle tags with a colon in the name.

Correction:

857: var match = /^<([\w:]+)\s*\/?>$/.exec(elems[0]);
874: elem = elem.replace(/(<([\w:]+)[^>]*?)\/>/g, function(all, front, tag){

      

+4


source


from what i understood you can try "selector in url syntax" to reload only certain parts of the page

$("#somediv").load(location.href + " #somediv");

      



plus, add a random parameter to avoid cache issues:

$("#somediv").load(location.href + "?r=" + Math.random() + " #somediv");

      

0


source


I can't see anything in firefox, and it's because this bit in the code is wrong:

google.load("jquery", "1.2.6");          //ok
google.setOnLoadCallback(function() {    //ok
   $(document).ready(function()          //not ok, can't be sure if will fire
      {  
         // great stuff here 
      }
   );
});

      

See this for clarification, the doc may be (indeed, in firefox) already read when LoadCallback is called from google.

If you can fix this bit, we can further examine it with firebug to find out where the script is located.

0


source







All Articles