Есть функция которая обрабатывает XML. response это выхлоп AJAX запроса ( xmlHttp.responseXML ). OpenPopup функция открывающая окошко с надписями. В FF работает все замечательно, но в IE response.getElementsByTagName('inc').length == 0. Почему? Я далеко не спец в JS, поэтому хорошо бы было указать причину и дать еще и ссылочку где почитать о данной ситуации. | Код | ReturnXML: function(response){ if(response.getElementsByTagName('inc').length > 0){ incId = response.getElementsByTagName('inc').item(0).getAttribute("id"); incTag = document.getElementById(incId); incVal = parseInt(incTag.firstChild.data) + parseInt(response.getElementsByTagName('inc').item(0).firstChild.data); incTag.firstChild.data = incVal; } OpenPopup(response.getElementsByTagName('head').item(0).firstChild.data,response.getElementsByTagName('body').item(0).firstChild.data); }
|
Сам XML. | Код | <?xml version="1.0" encoding="windows-1251"?><actions><head>Добавление товара в сравнение</head><body
>Товар добавлен к списку сравнения.</body><inc id='compare-count'>1</inc></actions>
|
На всякий пожарный весь JS | Код |
//==================================================================== // Init Ajax //==================================================================== var xmlHttp = CreateXmlHttpRequestObject();
function CreateXmlHttpRequestObject(){ var xmlHttp; try{ xmlHttp = new XMLHttpRequest(); } catch(e){ var XmlHttpVersion = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"); for(var i=0; i < XmlHttpVersion.length && !xmlHttp; i++){ try{ xmlHttp = new ActiveXObject(XmlHttpVersion[i]); } catch(e){} } } if(!xmlHttp) alert("Ошибка создания объекта XMLHttpRequest!"); else return xmlHttp; }
function process(action){ xmlHttp.open( "GET", "/bitrix/templates/interval/ajax/catalog.php?"+action, true ); xmlHttp.onreadystatechange = handleRequestStateChange; xmlHttp.send(null); }
function handleRequestStateChange(){ if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200){ try{ Actions.ReturnXML(xmlHttp.responseXML); } catch(e){} } } } //==================================================================== // PopUp Window //==================================================================== function CreatePopUpDiv(){ var div = document.createElement("div"); div.className = "popup-window"; div.id = "popup-window"; div.innerHTML = "<h4 id='popup-head'></h4>"+ "<p id='popup-body'></p>"+ "<input type='button' value='Закрыть' onclick='ClosePopup()'/>";
document.body.appendChild(div); } var Actions = { AddToCompare: function(id){ if(xmlHttp){ action = "action=ADD_TO_COMPARE&ELEMENT_ID="+id; process(action); } }, AddToBasket: function(id){ if(xmlHttp){ action = "action=ADD_TO_BASKET&ELEMENT_ID="+id; if(!document.getElementById('GoodsCount')){ document.getElementById('labelBasket').innerHTML = '<a class="BlueMenu" href="/personal/basket.php"> Товары в корзине: </a><label class="BlackInfo"><span id="GoodsCount">0</span> шт.</label>'; } process(action); } }, ReturnXML: function(response){ if(response.getElementsByTagName('inc').length > 0){ incId = response.getElementsByTagName('inc').item(0).getAttribute("id"); incTag = document.getElementById(incId); incVal = parseInt(incTag.firstChild.data) + parseInt(response.getElementsByTagName('inc').item(0).firstChild.data); incTag.firstChild.data = incVal; } OpenPopup(response.getElementsByTagName('head').item(0).firstChild.data,response.getElementsByTagName('body').item(0).firstChild.data); } } function OpenPopup(head,body){ if(!document.getElementById('popup-window')) CreatePopUpDiv(); popup = document.getElementById("popup-window"); document.getElementById("popup-head").innerHTML = head; document.getElementById("popup-body").innerHTML = body; popup.style.display = ""; popup.style.left = parseInt(document.body.clientWidth/2 + document.body.scrollLeft - popup.offsetWidth/2); popup.style.top = parseInt(document.body.clientHeight/2 + document.body.scrollTop - popup.offsetHeight/2); }
function ClosePopup(){ popup = document.getElementById("popup-window"); popup.style.display = "none"; }
|
Это сообщение отредактировал(а) Myp3uk - 30.7.2007, 17:46
|