Forgive my ignorance, but I can't figure out how to do a simple ajax request in PHP. I understand the principles of client-server communication in other languages/libraries, but PHP eludes me for some reason.
Here's what I'm trying to do:
Send a request from here, utilizing jQuery:
$(document).on('click', '#uploadAll', function() {
$.ajax({
url: '/ExamplePhpFile.php',
type: "POST",
data: {query:'INSERT INTO Assets SELECT * FROM Uploads'},
success: function(respose){
console.log("POST successful");
}
});
});
Get the query string in the data attribute here:
if(isset($_POST{'data'})) {
$query = $_POST['data'];
foreach($query as $value) {
echo 'here is your crap: '.$value;
}
}
Then I will use the passed query in another function to run an action on the server (this part works). Obviously I have something wrong, as the $_POST['data'] bit doesn't return a value. And monitoring $_POST by itself just gives me an array object (JSON_encode() doesn't do the trick on that either)
Can anyone offer me guidance, and save me some hair pulling? :)
dataas a key. It will havequeryas a key.$_POST['query']{}as inisset($post{'data'})... lol who knew.datawill not be a key in the$_POSTassociative array