Search code examples
phpjscript

How to load php file to specific place on site?


I have menu that is included and many other modules (leftside, rightside, content ect.).
I want to load some PHP page to specific place (content) on link click.


Solution

  • Use Ajax on button click and then fill the div in with the php from the ajax response.

    function dispRecords()
            {   
                if (window.XMLHttpRequest)
                {
                    // Create the object for browsers
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {
                    // Create the object for browser versions prior to IE 7
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function()
                {
                    // if server is ready with the response
                    if (xmlhttp.readyState==4) 
                    {
                        // if everything is Ok on browser
                        if(xmlhttp.status==200) 
                        {    
                            //Update the div with the response
                            document.getElementById("YOURDIV").innerHTML=xmlhttp.responseText;
                        }
                    }
                }
                //send the selected option id to the php page 
                xmlhttp.open("GET","YOURPHP.php",true);
                xmlhttp.send();
            }