Skip to content

Commit

Permalink
fix incorect key value pair on JSON response. shh x2.....
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjones-plip committed Dec 29, 2023
1 parent 498d4e9 commit f2fefd2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion html/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

foreach ($YANPIWS['labels'] as $id => $label) {
$tempsHtml .= "\t\t\t<div class='temp temp{$count}' id='temp{$count}'>" . get_json_inline('temp', $id) . "</div>\n";
$refreshTempJS .= "\t\trefreshData('temp&id={$id}',\t'#temp{$count}');\n";
$refreshTempJS .= "\t\trefreshData('temp&id={$id}',\t'#temp{$count}',\tfalse,\t'temp');\n";
$count++;
if ($count > $YANPIWS['temp_count']) {
break;
Expand Down
12 changes: 10 additions & 2 deletions html/js/YANPIWS.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@ function setClockSize(state, defaultSize){

/**
* AJAX call to get updated content and return JSON
* @param endpoint URL key where AJAX call lives on server
* @param target DOM element to push response into
* @param callback JS function to call upon success
* @param keyname if JSON key doesn't match endpoint, override with this
*/
function refreshData(endpoint, target, callback = false){
function refreshData(endpoint, target, callback = false, keyname = false){
let baseUrl = './ajax.php?content=';
$.getJSON( baseUrl + endpoint, function( data ) {
$(target).html(data[endpoint]);
// if no keyname was passed, use endpoint as keyname
if (keyname === false){
keyname = endpoint;
}
$(target).html(data[keyname]);
if (typeof callback === "function") {
callback();
}
Expand Down

0 comments on commit f2fefd2

Please sign in to comment.