DeathMatch Member
Posts : 6 Join date : 2011-03-26
| Subject: Ajax problem Sat May 14, 2011 7:40 pm | |
| Hello, first I have a code with ajax and cannot operate the onChange.ALso it cannot see the picture. - Code:
-
<select name="cs" onChange="ajaxRequest(this)">
<div id="result"> </div> - Code:
-
function ajaxRequest(){ var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken) for (var i=0; i<activexmodes.length; i++){ try{ return new ActiveXObject(activexmodes[i]) } catch(e){ //suppress error } } } else if (window.XMLHttpRequest) // if Mozilla, Safari etc return new XMLHttpRequest() else return false }
var mygetrequest=new ajaxRequest() if (mygetrequest.overrideMimeType) mygetrequest.overrideMimeType('text/xml') mygetrequest.onreadystatechange=function(){ if (mygetrequest.readyState==4){ if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){ var xmldata=mygetrequest.responseXML //retrieve result as an XML object var rssentries=xmldata.getElementsByTagName("pmdata") var output='<ul>' for (var i=0; i<rssentries.length; i++){ output+='<li>' output+='<a href="'+rssentries[i].getElementsByTagName('picture')[0].firstChild.nodeValue+'">' output+=rssentries[i].getElementsByTagName('name')[0].firstChild.nodeValue+'</a>' output+='</li>' } output+='</ul>' document.getElementById("result").innerHTML=output } else{ alert("An error has occured making the request") } } }
mygetrequest.open("GET", "http://outranet.scm.tees.ac.uk/users/u0000700/wes_ica_09_10/ukpm.php", true) mygetrequest.send(null)
in php file - Code:
-
<prime_minister> <pmdata> <name> Herbert Henry Asquith </name> </pmdata> <pmdata> <dates> 1908-16 </dates> </pmdata> <pmdata> <number> 35 </number> </pmdata> <pmdata> <picture> http://www.number-10.gov.uk/files/images/OLD%20PMs%20-%20H%20H%20Asquith.jpg </picture> </pmdata> </prime_minister>
|
|
Momment Member
Posts : 19 Join date : 2011-03-09
| Subject: Re: Ajax problem Sat May 14, 2011 7:41 pm | |
| |
|