interpim Posted November 5, 2008 Share Posted November 5, 2008 If you can't tell from the code below, i am a beginner at Ajax... can someone please explain to me what I am doing wrong. I've followed a couple of tuts but can't get anything back. I would be happy with getting anything back from the backend php file LOL. I can adjust the code to give me what I need, but basically all i need is to click a button or link to increment a number and return a url based on that number. this is my html page <SCRIPT Language="JavaScript"> function getHTTPObject() { var xmlhttp; if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } } return xmlhttp; } var http = getHTTPObject(); function ajaxFunction(somevar){ http.open('GET', 'ajax.php?pic='+pic, true); http.send(null); http.onreadystatechange=function(){ if(http.readyState==4){ document.getElementById('somediv').innerHTML = http.responseText; // this will put the returned code from ajax.php into a div with id "somediv" } } } </script> <div name='somediv'> </div> <p> <p><a href="javascript: ajaxFunction('somediv','pic')">Click to Test</a></p> </p> Here is ajax.php <?php $pic = $_GET['pic']; if($pic == ''){ $pic = 1; } $pic = $pic + 1; echo "<img src=" . $pic . ">"; ?> Quote Link to comment Share on other sites More sharing options...
interpim Posted November 5, 2008 Author Share Posted November 5, 2008 OK... so i realized i needed to change my div to an id and not a name and i can get info back now. but, i want to increment a number... how do i pass what is currently showing in the div back to the php file to increment? 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.