Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
Call another page using AJAX in php on onClick()
Sponsered Links
Categories
Sponsered Links

Call another page using AJAX in php on onClick()

This example illustrates how to call another page on onClick() function to display the record. By another page we fetching record from mysql database.

<script language="JavaScript" type="text/javascript">
        function stateChanged() {
            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                document.getElementById("result").innerHTML=xmlHttp.responseText;
            }
        }       
        // Get State
        function GetState(str) {
            xmlHttp=GetXmlHttpObject()
            if (xmlHttp==null) {
                alert ("Browser does not support HTTP Request");
                return
            }           
            var url="state.php";
            url=url+"?cnt="+str;
            url=url+"&sid="+Math.random();
            xmlHttp.onreadystatechange=stateChanged_;
            xmlHttp.open("GET",url,true);
            xmlHttp.send(null);
        }
        function stateChanged_() {
            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                document.getElementById("state1").innerHTML=xmlHttp.responseText;
            }
        }
        function GetXmlHttpObject(){
            var xmlHttp=null;
            try    {
                // Firefox, Opera 8.0+, Safari
                xmlHttp=new XMLHttpRequest();
            } catch (e) {
                //Internet Explorer
                try {
                    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
            }
            return xmlHttp;
        }      
</script>

 

<input type="text" name="city" onClick="GetState('United States')"/>

<div id="state1"></div>

Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved