Jump to content

ajax and php not talking


purencool

Recommended Posts

Hi phpfreaks,

 

I have been playing with  ajax and I have decided that it is not working. I pulled the ajax from w3C and on trialing it worked fine.

I then add the function checkdomain. This function adds takes the variable from the form and then places it into the showUser function. The alert box

in showUser always shows the right variable and if I test the php file by itself it also is working. Can anyone see an issue in this code.

 

<script type="text/javascript">
    function showUser(str)
    {
       //alert(str);
       if (str=="")
        {
            document.getElementById("txtHint").innerHTML="";
            return;
        }
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
            }
        }
        alert(str);
        xmlhttp.open("GET","searchdomain.php?search="+str,true);
        xmlhttp.send();
    }

function checkdomain (){
    var str = document.getElementById ("search");   
    return str.value;
}


</script>
</head>
<body>

<br />
<form id="domain" method="get"  onsubmit="showUser(checkdomain())">
    <p>Domain Search: <input type="text" id="search" name="search" value=""/><input type="submit"  value="Go"/>
    </p>
</form>

Link to comment
https://forums.phpfreaks.com/topic/233334-ajax-and-php-not-talking/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.