Hi guys i have small problem , plz help me. when i put the direct URL address, it works. If pass that URL address and try to use it wont work. here is the code. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> <script type="text/javascript"> <!-- //Create a boolean variable to check for a valid Internet Explorer instance. var xmlhttp = false; //Check if we are using IE. try { //If the Javascript version is greater than 5. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); alert ("You are using Microsoft Internet Explorer."); } catch (e) { //If not, then use the older active x object. try { //If we are using Internet Explorer. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); alert ("You are using Microsoft Internet Explorder"); } catch (E) { //Else we must be using a non-IE browser. xmlhttp = false; } } //If we are using a non-IE browser, create a javascript instance of the object. if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { xmlhttp = new XMLHttpRequest(); alert ("You are not using Microsoft Internet Explorer"); } function callfunc(serverPage,num,objID) { var obj = document.getElementById(objID); //xmlhttp.open("GET", "serverPage?urlname=" + num, true); not working //if i give the URL name directly here, it works xmlhttp.open("GET", "content1.php?urlname=" + num, true); //works xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { obj.innerHTML = xmlhttp.responseText; } } xmlhttp.send(null); } //--> </script> </head> <body> <?php echo "This is my first example <br>"; ?> <a href="#" onclick="callfunc('content1.php','6','url'); return false;">CLICK HERE</a> <div id="url"> </div> </body> </html>
Are you calling the variable right in the php script? Example: <?php if (!empty($_REQUEST['VARIABLENAME'])) { $variable = trim($_REQUEST['VARIABLENAME']); } else { die('variable not sent correctly.'); } ?>
If i understand well serverPage is a javascript variable passed by the function callFunc. Instead of xmlhttp.open("GET", "serverPage?urlname=" + num, true); do xmlhttp.open("GET", serverPage+"?urlname=" + num, true); Javascript doesn't parse like PHP! A nice way to avoid problems is... to create others!!!
This should be working! What does it display when you write alert(serverPage); before calling the open function? does it display content1.php? You can also do like this to check if what you want is correctly called: var url = serverPage+"?urlname=" + num; alert(url); xmlhttp.open("GET", url, true);
get firefox and firebug, look at error console (press f12), you can also set breakpoints and watch variables. what webricko said is correct and should work, if you are unsure, just copy and paste xmlhttp.open("GET", serverPage+"?urlname=" + num, true); http://getfirebug.com/ - firebug is a plugin for debugging JS,walking DOM and CSS / eidting on the fly. There is a plugin for firebug called firePHP which works on the basis of additional headers and can output debug information to the browser console.