Question

I have a PHP Script to update a database, I have the PHP Side nailed down, but the JS I'm having a little bit of trouble with. Below is my code:

$JSON = json_decode($Arg);
$Username = $JSON['Username'];
$Page = $JSON['Location'];

$Query = $MySQLi->prepare("INSERT INTO Requests (username, page) VALUES (?, ?)");
$Query-> bind_param("ss", $DUsername, $Page);
$Query->execute();

$Query_2 = $MySQLi->query("UPDATE RequestStats SET Count = Count+1, LastRequest='NOW()'");

And on the user side,

if (isset($_POST['Request']))
{
 $EmptyArray = array();
 $EmptyArray[] = $Username;
 $EmptyArray[] = $_SERVER['REQUEST_URI'];
 json_encode($EmptyArray);
}

What I need done, is calling a Javascript/AJAX chunk to forward over the request to my external page, and dynamically update the database without a refresh.. After the request is made, echo out a box saying "your request has been made, and you are number: number inline"

I have no idea on how to do this, could anyone provide some assistance?

Was it helpful?

Solution

This can be completed by using JQuery... View the manual for what i've used: http://api.jquery.com/click/

Userside:

<body>
<div id="test">
<input type="button" value="Make A Request">
</div>


<script>
$("#test").click(function () {
    $.ajax({
        url: 'page.php',
        success: function(){
             alert('Created');
        }
    });
    return false;
});
</script>
</body>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top