Announcement

Collapse
No announcement yet.

how to auto refresh a page, and get a callback to postbackproc

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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?
    Mark

    HS3 Pro 4.2.19.5
    Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
    Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
    Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

    #2
    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

    Comment


      #3
      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 can't debug the eval call

      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);


      Mark

      HS3 Pro 4.2.19.5
      Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
      Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
      Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

      Comment


        #4
        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);

        almost .....

        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 ....!!!

        Comment


          #5
          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");
                  }
              });

          Comment


            #6
            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");
                            }
                        });

            Comment


              #7
              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);
              }
              });
              Mark

              HS3 Pro 4.2.19.5
              Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
              Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
              Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

              Comment


                #8
                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?

                Comment


                  #9
                  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?
                  Mark

                  HS3 Pro 4.2.19.5
                  Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
                  Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
                  Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

                  Comment


                    #10
                    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?

                    Comment


                      #11
                      Originally posted by mnsandler View Post
                      Yes, i have been using the chrome debugger. its really no help - i
                      Does the network (tab) show your page posting and is there no response?

                      Comment


                        #12
                        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


                        Attached Files
                        Mark

                        HS3 Pro 4.2.19.5
                        Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
                        Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
                        Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

                        Comment


                          #13
                          Originally posted by mnsandler View Post
                          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

                          You do. In R4.2 driven by security issues (or so I understood), HS will not respond to POSTs to a URL that is not registered (actually common sense). If you don't want them to show in your menu, register them linkText ="" You should see a message going out if you use the browser debugger and seem to recall a 404 response. I ran into this when everything working in R41 stopped working in R42, URL must be registered.

                          Comment


                            #14
                            ok. i registered the statuspage.html but still not joy. the plugin isn't being called and thus to status
                            Attached Files
                            Mark

                            HS3 Pro 4.2.19.5
                            Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
                            Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
                            Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

                            Comment


                              #15
                              Just loaded your html file. I had to rename it to something I have registered with HS (including your links in the javascript and it works here.
                              You can click on the entry to see the parameters , inspect the URL .. I think it shows you do send the POST but get no response, so either URL is incorrect or registeration is incorrect.

                              Comment

                              Working...
                              X