hasjem Posted May 9, 2010 Share Posted May 9, 2010 I am busy learning ajax and i picked up a "simple" script from the internet. if i understand this i can alter it and use it. but it doesn't work and i do not see why. if i have a working script i can go on but as long as i do not understand why it isn't working.... who can point the mistake? <script language="JavaScript" type="text/javascript"> 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) } catch(e){ //suppress error } } } else if (window.XMLHttpRequest) // if Mozilla, Safari etc return new XMLHttpRequest() else return false } </script> <script language="JavaScript" type="text/javascript"> var mygetrequest=new ajaxRequest() mygetrequest.onreadystatechange=function(){ if (mygetrequest.readyState==4){ if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){ document.getElementById("result").innerHTML=mygetrequest.responseText } else{ alert("An error has occured making the request") } } } var namevalue=encodeURIComponent(document.getElementById("name").value) var agevalue=encodeURIComponent(document.getElementById("age").value) mygetrequest.open("GET", "basicform.php?name="+namevalue+"&age="+agevalue, true) mygetrequest.send(null) </script> <form method="get" action=""> Your name: <input type="text" id="name" name="name" size="25" /> <br /> Your age: <input type="text" id="age" name="age" size="25" /> <br /> <input type="button" value="submit" onClick="ajaxget()" /> </form> <div id="result"> </div> and as basicform.php: <? $name=htmlspecialchars($_GET['name']); $name=stripslashes($name); $age=(int)$_GET['age']; echo "<span style='color:red'>Welcome <b>$name</b> to JavaScript Kit. So you're <b>$age</b> years old eh?</span>"; ?> Quote Link to comment Share on other sites More sharing options...
F1Fan Posted May 9, 2010 Share Posted May 9, 2010 Please post code in the code tags. It makes it much easier to read. So what problem are you having, other than "it isn't working?" The more details, the better. At first glance, it appears that your button is calling a function called "ajaxget()," but there is no such function. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.