user7393973 user7393973 - 2 years ago 62
HTML Question

How to use PHP withouth reloading the page

I have the following files with their respective code:


<iframe id="frame1" style="display:none"></iframe>
<iframe id="frame2" style="display:none"></iframe>
<button onClick="document.getElementById('frame1').src='Create.php'">Create</button>
<button onClick="document.getElementById('frame2').src='Drop.php'">Drop</button>


mysqli_query(new mysqli('localhost','root'),'create database `db1`')


mysqli_query(new mysqli('localhost','root'),'drop database `db1`')

What they do is make a button that creates a database when clicked and another one that deletes that same database (named
). My problem is getting it to work without having to reload the page.

Answer Source

In this case you should use AJAX. Onclick you can send a xmlhttprequest (JS) to a separate php file, which is executed.


function test()
    xhr = new XMLHttpRequest();"GET","your_ajax_file.php",true);

your_ajax_file.php can create / drop the database.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download