AJAX是否可以在PHP文件上使用?

I'm working on AJAX on PHP file but it doesn't work but it works on HTML file.

I have my AJAX function here

        function search(shopName)
        {
            var xmlhttp;

            if (window.XMLHttpRequest)
            {
                xmlhttp=new XMLHttpRequest();
            }

            else
            {
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }

            xmlhttp.onreadystatechange=function()
            {
                if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                    document.getElementById("search").innerHTML=xmlhttp.responseText;
                }
            }

            xmlhttp.open("GET","http://localhost:8080/User/newjsp.jsp?shopName="+shopName,true);
            xmlhttp.send();
        }

Here is the form for it when user inputs

    <form action="">
        Search shop name : <input type="text" onkeyup="search(this.value)"/>
    </form>

    <div id="search">A</div>

Now, the thing is that it works well on HTML file I've create. I even did copy and paste from the PHP to HTML file. It works on HTML but it fails on PHP file.

My question is that does AJAX works on PHP file? If so, can anyone guide me to the correct method or what is my mistake.

Your question is little vage because javascript (like ajax) is client side, it is executed by the browser just like html and css. php is a server side scripting language and is unrelated with what happens in the clients browser. So asking if an ajax call can work inside a php file is kind of awkward.

so to answer your question. No it is not possible that an ajax call can work inside a php file.