javascript - JQuery ONLY works in compatibility mode -


i working on creating web application displayed on local intranet site
nb using ie11
takes information xml file , cycles through it, displaying each section in turn. have had use old version of jquery in order make work on system it'll running on, using 1.12.4. problem page pulls in information in first instance, after nothing. quick check in debugging console tells me page unable property 'childnodes' of undefined or null reference - seems strange me works in first instance. if run page in compatibility view, script works properly, destroys of styling etc. there way fix or going have deal awful compatibility view styled page?
my code below
html

<div id="mainnews">     <div class="panel panel-default" id="mainnewsstory">         <h1 id="storyheadline"></h1>         <p id="storybody"></p>     </div>     <img id="storyimage" src=""/> </div> 

xml

<newsarticle> <story>     <storyheadline>this headline of first news story!</storyheadline>     <storybody>this body of first news story. lorem ipsum dolor sit amet, consectetur adipiscing elit. nullam id nunc ex.</storybody>     <storyimage>images\imageone.png</storyimage> </story> <story>     <storyheadline>this second headline! accompanies second story</storyheadline>     <storybody>this body of second news story. lorem ipsum dolor sit amet, consectetur adipiscing elit. nullam id nunc ex.</storybody>     <storyimage>images\imagetwo.png</storyimage> </story> <story>     <storyheadline>this third headline now!</storyheadline>     <storybody>this body of third news story. lorem ipsum dolor sit amet, consectetur adipiscing elit. nullam id nunc ex.</storybody>     <storyimage>images\imagethree.png</storyimage> </story> 

javascript

$(function(){ $.ajax({     type: "get",     url: "setscreen.xml",     datatype: "xml",     success: parsexml });  function parsexml(xml) {     //--fill content in main news story start--//     var storycount = 0;     var xstories = xml.getelementsbytagname("storyheadline");     var xstorybody = xml.getelementsbytagname("storybody");     var xstoryimage = xml.getelementsbytagname("storyimage")     var maxstories = xstories.length;     function fillstory(){         $('#storyheadline').html(xstories[(storycount) % maxstories].childnodes[0].nodevalue);         $('#storybody').html(xstorybody[(storycount) % maxstories].childnodes[0].nodevalue);          $('#storyimage').prop("src", xstoryimage[(storycount++) % maxstories].childnodes[0].nodevalue);     }     //--fill content in main news story end--//      fillstory();     var storytimer = setinterval(fillstory, 2000); } }); 

any appreciated.

edit: original 'fix' stopped working after 5 page loads, delved little deeper, , managed find root(s) of problem.


turned out combination of couple of things. managed force page styling , remain normal in compatibility view using

<meta http-equiv="x-ua-compatible" content="ie=edge" /> 

as first tag in <head>. solved awful styling problem, if page forced compatibility view. source here.



contributor problem had xml file contained following header can apparently break in ie.

<?xml version="1.0" encoding="utf-8" ?> 

so removing allowed javascript run. source.



final problem had once javascript running, run few times before stopping, , tell me couldn't access variables trying to. first tried declaring variables inside function, meant declared every time function ran, caused unsightly memory issues. moved declaring variables outside of function, assigning values inside.

var storycount = 0;     var xstories, xstorybody, xstoryimage, maxstories;     function fillstory() {         xstories = xml.getelementsbytagname("storyheadline");         xstorybody = xml.getelementsbytagname("storybody");         xstoryimage = xml.getelementsbytagname("storyimage");         maxstories = xstories.length;         $("#storyheadline").html(xstories[(storycount) % maxstories].childnodes[0].nodevalue);         $("#storybody").html(xstorybody[(storycount) % maxstories].childnodes[0].nodevalue);         $("#storyimage").prop("src", xstoryimage[(storycount) % maxstories].childnodes[0].nodevalue);         storycount = storycount + 1; 

so works want to!


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -