Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.