Saturday, 15 June 2013

javascript - Ajax response received in Internet Explorer but not in Chrome: -



javascript - Ajax response received in Internet Explorer but not in Chrome: -

for reason next code works in net explorer not in chrome or firefox. in browsers receive the:

"not able retrieve sliders data."

alert.

i love help one.

thanks.

here javascript code:

<script> if (navigator.appname == "microsoft net explorer") { request = new activexobject("microsoft.xmlhttp"); } else { request = new xmlhttprequest(); } if (request == null) alert ("your browser doesn't back upwards xmlhttprequest"); function getselectedtext(elementid) { var elt = document.getelementbyid(elementid); if (elt.selectedindex == -1) homecoming null; homecoming elt.options[elt.selectedindex].value; } function sendrequest() { debugger; var type = getselectedtext('dropdown'); //alert("the chosen type: "+type); var url = 'https://tomcat-emildesign.rhcloud.com/coupons/client/serveranswer.jsp?type=' + type; request.open("get", url, true); request.onreadystatechange= processrequest; request.send(null); } function processrequest() { if (request.readystate == 4) { if (request.status == 200) { parsemessage(); } else { alert ( "not able retrieve sliders data." ); } } } function parsemessage() { // assign xml file var variable. var doc = request.responsexml; var pending, hires, rejected; if(navigator.appname == "microsoft net explorer") { pending = doc.documentelement.getelementsbytagname('pending').item(0).text; hires = doc.documentelement.getelementsbytagname('hires').item(0).text; rejected = doc.documentelement.getelementsbytagname('rejected').item(0).text; } else { pending = doc.documentelement.getelementsbytagname('pending')[0].textcontent; hires = doc.documentelement.getelementsbytagname('hires')[0].textcontent; rejected = doc.documentelement.getelementsbytagname('rejected')[0].textcontent; } alert("values:" + pending + "," + hires + "," + rejected); }

i don't see wrong code. issue might doing cross-domain request trusted in net explorer fails in other browsers.

to confirm this, can check if returned request.status equal 0.

more info on same origin policy on wikipedia.

javascript xml-parsing xmlhttprequest

No comments:

Post a Comment