After sending an Ajax post request, I get an array as a response. I want to use this array in another function, I tried to declare the variable before setting its value without putting it in any function.
var their_Info = [];
$.ajax({
url: "My PHP url",
type: "post",
data: {username:usernames} ,
success: function (response) {
their_Info = JSON.parse(response);
});
If I want to use their_Info in a separate function I am getting undefined..
Below is the php script for reference:
<?php
header('Access-Control-Allow-Origin: *');
$usernames = $_POST['username'];
//$ids = join("','",$usernames);
$link = mysqli_connect("localhost", "root", "vKukRKWZRE", "table");
$acc_Info = array();
foreach ($usernames as $value) {
$query = "SELECT * FROM users WHERE username = '$value'";
$show = mysqli_query($link, $query) or die("Error");
while ($row = mysqli_fetch_array($show)) {
array_push($acc_Info, explode(',', $row['wear']));
}
}
echo json_encode($acc_Info);
?>