Russel Riehle Russel Riehle - 1 year ago 53
PHP Question

Call URL with querystring and recieve return from this page

I have a button on my user.php page. This button must call action.php?name=john&id=10 onclick without refresh the page.

The page action.php should proccess this querystring data (name=john & id=10), perform some action and send an message back..

user.php example:

<button onclick="callAction()">Do it!</button>

function callAction() {
//call action.php?name=john&id=10

action.php example:

$name = $_GET['name'];
$id = $_GET['id'];

if(id == 10) {
//send user.php some successful text
} else {
//send user.php some error text


Any idea? Thanks a lot!

Answer Source

Using jQuery you can make the ajax call like:

$.get('action.php?name=john&id=123', function (data) {
    console.log('response: ', data);

Here is the documentation:

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