i do register three feature pages using RegisterFeaturePage so they show on HS UI, but i didn't think i needed to register every .html file I use.
here is the statuspage.html - nothing special
Announcement
Collapse
No announcement yet.
how to auto refresh a page, and get a callback to postbackproc
Collapse
X
-
Do you want to email me (PM) your html file so I can see all you are doing.
When you say you haven't registered your HTML page (RegisterFeaturePage), in R4.2 you must or it won't work, but perhaps we are saying different things?
Leave a comment:
-
Yes, i have been using the chrome debugger. its really no help - i can't get any error message back from the ajax call, or from the debugger
the initial slash / is required when you call ajax directly. ajaxpost adds the initial / for you
i haven't registered any of my custom html pages, and they all display and postback just fine.
this is my first attempt to have a page refresh itself (so i can display status message). i had this working and then upgraded to hs 4.2.5 and it broke.
is your installation using "jquery-3.4.0.min.js"?
i dont know what version of bootstrap hs4.2.5.0 installs?
Leave a comment:
-
Did you turn the debug fiunction of the browser on? Did you see an error 404?
At first glance use Insteon/statuspage.html as the URL and drop the / You have that URL registered with HS right?
Leave a comment:
-
below is my basic ajax call (got rid of using ajaxpost) on my auto-refresh page (Insteon/statuspage.html)
i want this to call back to the plugin via postbackproc, but the ajax call generates an error, so nothing happens
"jquery-3.4.0.min.js" is being called
what am i missing?
Code:$.ajax({ type: "POST", async: "true", url: "/Insteon/statuspage.html", cache: false, data: "", success: function (response) { if (response == "") { window.location.href = "/Insteon/statuspage.html"; } else { alert(response); return; } }, error: function () { //alert(result); } });
Leave a comment:
-
Here is another example, because the above was based on JSON, this is more like HS does it
Code:function AjaxPost_(data,page){ if (instance != "") { if (data != "") { data=data+"&" } data = data+"instance="+instance } $.ajax({ type: "POST", async: "true", url: '/'+page, cache:false, data: data, success: function (response) { if (response == '') { after_postback(); return; } var sResponse; sResponse = eval('(' + response + ')'); //alert(response); for(i=0; i<sResponse.length; i+=2) { if(sResponse[i]==null) continue; if(sResponse[i].substr(0,5) == 'PAGE_') { var pageCmd=sResponse[i].substr(5); switch(pageCmd.toLowerCase()) { case 'popmessage': alert(sResponse[i + 1]); after_postback(); break; case 'newpage': location.assign(sResponse[i+1]); break; case 'refresh': // alert(sResponse); if(sResponse[i+1].toLowerCase() == 'true') { returnTrue = true; location.reload(); } break; } } else { if(sResponse[i].substr(0,13) == 'navigatemore_') { var itemTable = document.querySelector ("#sonosplayernav > tbody "); itemTable.removeChild (itemTable.lastChild); itemTable = itemTable.innerHTML + sResponse[i+1]; $('#sonosplayernav > tbody ').empty(); $('#sonosplayernav > tbody ').html(itemTable); } else{ if ( (muteSliderUpdates > 0) && ((sResponse[i].substr(0,22) == 'playertrackpositiondiv') || (sResponse[i].substr(0,29) == 'playertrackcurrentpositiondiv') || (sResponse[i].substr(0,20) == 'playertracklengthdiv')) ) { // no updating! } else { $('#' + sResponse[i]).empty(); $('#' + sResponse[i]).html(sResponse[i+1]); after_postback(); } } } } }, error: function(){ // alert("Error"); } });
Leave a comment:
-
Ok, maybe to be clear ....
Your AJAX call from your html page, you should put in the information what is important to you, it needs to use a URL that your PI has registered to, so you get a postback call.
In response, you can use ["PAGE_refresh", "TRUE"] , upon received by the javacode in your html page, will trigger a refresh .... provided you use the same function HS is using.
Does that make sense?
So the code above AjaxPost("PAGE_refresh", true) I guess is wrong. Here is my code
Code:function AjaxPost_(data,page){ $.ajax({ type: "POST", async: "true", url: '/'+page, cache:false, data: data, success: function (response) { if (response == '') { return; } var resObj = jQuery.parseJSON(response); switch(resObj.result) { case 'error' : alert(resObj.error); event.stopPropagation(); break; case 'refresh': location.reload(); break; case 'copy' : // copy to clipboard //navigator.clipboard.writeText (resObj.copy); textToClipboard (resObj.copy); alert("Copied!"); break; case 'editsourceplayerdiv' : // update sourceplayer list $('#editsourceplayer').empty(); $.each(resObj.sourcePlayers, function (i, item) { $('#editsourceplayer').append(item.sourcePlayerXML); }); // update destination list UpdateDestinationPlayers(); break; case 'updatedivs': $.each(resObj.updateDivs, function (i, item) { $('#'+item.divId).empty(); $('#'+item.divId).append(item.updateDivInfo); }); break; case 'openwindow' : var devicesPage = resObj.actionInfo; window.open(devicesPage); //window.location.assign (devicesPage); break; } }, error: function(){ alert("Error with response"); } });
Leave a comment:
-
Originally posted by mnsandler View Post
Question: with the standard ajaxPost call on my status.html page (which auto freshes), shouldn't i be able to make the following call to have the ajaxpost make a callback to callbackproc?
AjaxPost("PAGE_refresh", true);
AjaxPost(["PAGE_refresh", "TRUE"]);
I stopped using this "baked in ajax function, concerned that, if changed by the HS team, your functions start to fail. So in some of my html pages, I verbatim copied the javascript ajax functions, so if HS changes theirs, mine still work. In other html pages, I stepped away from this key/value principle in favor of JSON structured information.
edit: this is actually the response from your PI ....!!!
Leave a comment:
-
Dirk,
Can't we use the standard HS ajaxPost() found in the bootstrap/js/page_common.js file? its generating an Error in the following line, and thus exiting
Code:sResponse = eval('(' + response + ')');
i read through the following thread but you guys are getting a little more complex than i need right now
https://forums.homeseer.com/forum/de...in-featurepage
Question: with the standard ajaxPost call on my status.html page (which auto freshes), shouldn't i be able to make the following call to have the ajaxpost make a callback to callbackproc?
AjaxPost("PAGE_refresh", true);
Leave a comment:
-
If you use Chrome, turn on the debugger tool and watch for errors. Put in a couple of log statements in your javascript so you can verify you use the right URL. Make sure the URL is a registered URL in HS4
Leave a comment:
-
how to auto refresh a page, and get a callback to postbackproc
i have a status.html page that I have setup to auto refresh. i would like to have the status page call ajaxpost on each refresh
i have tried several variations of the ajaxpost call, but it wont call postbackproc. the ajaxpost call seems to exit, and do nothing
i can get a postbackproc call from an ajaxpost call after an on click event. so i know it works.
suggestions?Tags: None
Leave a comment: