I'm very new to html/css/javascript/php and everything related. I only really know java. Currently, I have a page set up in html (mattrb.com/cs) that posts data to a php page that calls an api and displays some data. The html is:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta content="#db5945" name="theme-color">
<!--<link type="text/css" rel="stylesheet" href="layout-styles.css"/>-->
<title>float check</title>
<style>
body {
background-color: #222222;
color: #db5945;
}
#footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
text-align: center;
color: #042E64;
background-color: #222222;
height: 18px;
}
</style>
</head>
<body>
<form action="apitest.php" method="post">
<input type="text" name="id" placeholder="id">
<input type="submit">
</form>
<div id="footer">
<a href="http://steampowered.com">Powered by Steam</a>
</div>
</body>
</html>
and the php file called is:
<html>
<head>
<meta content="#db5945" name="theme-color">
<style>
body {
background-color: #222222;
color: #db5945;
}
</style>
</head>
<body>
<?php
$apikey = "XXXXXX-STEAM-API-KEY-XXXXX";
$input = $_POST["id"];
while (substr($input, strlen($input) - 1) == "/" || substr($input, strlen($input) - 1) == " ") {
$input = substr($input, 0, strlen($input) - 1);
}
$steamid = "";
function isInteger($input){
return(ctype_digit(strval($input)));
}
if (strpos($input, "/id/") !== false || isInteger(substr($input, strlen($input) - 17)) == false) {
$pos = 0;
if (strpos($input, "/id/") !== false) {
$pos = strrpos($input, "d/") + 2;
}
$vanityurl = substr($input, $pos);
$steamidAPI = "http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=" . $apikey . "&vanityurl=" . $vanityurl;
$responseid = json_decode(file_get_contents($steamidAPI));
$steamid = $responseid->response->steamid;
} else {
$steamid = substr($input, strlen($input) - 17);
}
echo("steamid: " . $steamid . "<br><br>");
$playerItemsAPI = "http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?key=" . $apikey . "&SteamID=" . $steamid;
do {
$playerItems = json_decode(file_get_contents($playerItemsAPI));
} while (is_null($playerItems));
$inventoryAPI = "http://steamcommunity.com/profiles/" . $steamid . "/inventory/json/730/2";
$inventory = json_decode(file_get_contents($inventoryAPI));
$names = array();
$float = array();
$cases = 0;
$keys = 0;
for ($i = 0; $i < count($playerItems->result->items); $i++) {
$id = $playerItems->result->items[$i]->id;
$classid = $inventory->rgInventory->$id->classid;
$instanceid = $inventory->rgInventory->$id->instanceid;
$combination = $classid . "_" . $instanceid;
$name = $inventory->rgDescriptions->$combination->market_name;
if(substr($name, strlen($name) - 3, strlen($name)) == "Key") {
$keys++;
} else if (substr($name, strlen($name) - 4, strlen($name)) == "Case") {
$cases++;
} else {
array_push($names, $name);
if ($playerItems->result->items[$i]->attributes[2]->defindex == 8) {
array_push($float, $playerItems->result->items[$i]->attributes[2]->float_value);
} else {
array_push($float, 0);
}
}
}
$tab = " ";
for ($j = 0; $j < count($names); $j++) {
$someOutput = true;
echo(strtolower($names[$j]) . "<br>");
if ($float[$j] != 0) {
echo($tab . $float[$j] . "<br>");
}
}
echo("items: " . (count($names) + $keys + $cases) . "<br>");
echo("items discounting keys/cases: " . count($names) . "<br>");
echo("keys: " . $keys . "<br>");
echo("cases: " . $cases . "<br>");
echo("<br>if you expected something to<br>show up and nothing did, check<br>your inventory privacy settings");
?>
</body>
</html>
This is everything I have right now. My goal is to use ajax to update the information on the html page with the data from the php file using ajax without refreshing the page. Is this possible? If so, how would I go about it?
Thanks!