I'm trying to get my AJAX request to PHP working. It should, after sending the AJAX request loop through some items and then send back an array of data. The problem is that it returns an empty string.
Here's the code:
PHP
if(isset($_POST['action']) && !empty($_POST['action'])) {
$available = array();
for($i = 0; $i <= 50; $i++) {
$gt = substr(md5(microtime()),rand(0,26),3);
$check_url = "SOMEURL" . $gt . ".card";
$check_url_source = file_get_contents( $check_url );
$exists = ( preg_match( "#<div id=\"Gamerscore\">--</div>#i", $check_url_source ) ) ? false : true;
if($exists == false) {
array_push($available, $gt);
}
}
echo json_encode($available, JSON_FORCE_OBJECT);
}
JQuery
$('document').ready(function() {
$.ajax({
url: '/GamertagChecker/helpers/magic.php',
data: {action: 'load'},
type: 'post',
success: function(output) {
console.log(output);
},
error: function(jqXHR, exception){
console.log("Error: " + jqXHR.responseText);
}
});
});