Russel Riehle Russel Riehle - 1 month ago 4
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:

<?php
$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

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: https://api.jquery.com/jquery.get/

Comments