Announcement

Collapse
No announcement yet.

Processing POST response

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

    Processing POST response

    I've created a package of reports some people might find useful, others will not. The installer and Custom Report Documentation docs are attached. I had to remove a fair amount of the data from the Custom Report Documentation file due to size constraints to upload files but you can probably get a general idea of the reports.

    I have one last hurdle to resolve before I try to find if anybody wants to test it out. If it's usable, I will then figure out how to make it freely available.

    To update a config file, I need to process a POST string. I've tried to make sense of hs3_ajax_post.js but cannot get anywhere with it.

    The process is:
    1. The user clicks on the Config button on databaseReports.html (attached html file).
    2. That opens databaseConfig.html.
    3. The user selects a report type then Submit.
    4. The POST is returned to databaseReports.html which submits it to the csUpdateIniFile.cs script

    An example of the POST returned to databaseReports.html is: databaseReports.html?contactRange=numOfDays&days=1&startDate =&endDate=

    The POST data needs to end up to the C# script named csUpdateIniFile.cs which parses the POST string and updates the "DB Report Config.ini" file.

    I'm hopeful someone can let me know what I need to do to process the POST response either by way of databaseReports.html or sending it directly to csUpdateIniFile.cs.

    Attached Files

    #2
    Is it similar to Jon00 Event Viewer & Documenter for Homeseer 4?

    Comment


      #3
      Originally posted by alexbk66 View Post
      I took a quick look at all the messages in the link, but I did not see anything about how a HomeSeer webpage processes a POST request. I'll go through it again.

      I'm still reading more about how AJAX and Jquery work to process a POST request. I'm not a web programmer (heck, I'm not really any kind of programmer) so the learning curve is a bit steep.

      Comment


        #4
        I've started going through a couple different AJAX training sites trying to figure out all the pieces. It's clear my request for assistance was not practical. It will take me awhile, but I'll figure it out.

        Comment


          #5
          Your request is not clear - what exactly you want help with?

          Comment


            #6
            At this point, I'm trying to do a lot more learning about AJAX and JQuery. When I look back at my original request, it's almost like I was asking someone to do my work for me... which was not my intent.

            I attached a picture of what I am trying to do along with the two webpages:

            Click image for larger version

Name:	Update Config file.jpg
Views:	116
Size:	60.9 KB
ID:	1599447

            1. User clicks Config button on databaseReports.html which opens databaseConfig.html on client computer
            2. User submits form which returns to databaseReports.html
            3. JQuery code sends request to csUpdateIniFile.cs c# script
            4. csUpdateIniFile.cs c# script updates DB Report Config.ini file

            So far I have not been able to get the HS4 device to even acknowledge the response I send back when I submit the form.

            I also tried using .aspx. It seemed promising but it kept hanging which required me to reboot my HS4 device (restarting HomeSeer would not clear the issue).

            I'm currently going through every training site I can find, but it appears the HS4 AJAX configuration is different than what they use.
            Attached Files

            Comment


              #7
              I have two problems:
              1. I don't know how to grab the POST and assign it to POSTval.
              2. What should .function() be? run.function() or perhaps function()?

              I've been trying to do the following in databaseReports.html with different variations for function(), but if I cannot assign the POST to POSTval I'm just spinning my wheels.

              Code:
              <script>
              $('#home').function(){
              let scriptname = 'csUpdateIniFile.cs';
              let fucn = 'csUpdateDatabaseIniFile';
              let param = 'POSTval';
              $(document).ready(function(){
              AjaxPost("action=run_script_command&scriptcommand=%26hs.runs criptfunc(%22" + scriptname + "%22%2C%22" + fucn + "%22%2C%22" + param + "%22%2CFalse%2CFalse)","runscript.html");
              });
              });
              </script>​
              For the second part, I've also tried:
              Code:
              <script>
              $('#home')ready.(function(){
              function myFunction()}​

              Comment


                #8
                The second part is resolved. It's as simple as:

                Code:
                $('#home').ready(function(){
                I was missing the leading "." in front of "ready"

                Still working on figuring out how to get the POST data to the c# script. I seem to be making some progress but now I'm leaning towards creating and calling a .js file in the js directory.

                Comment


                  #9
                  The example plugin shows how this can be done - basically in your JS:

                  Code:
                  $.ajax({
                      type: "POST",
                      async: "false",
                      url: "PluginID/page.html",
                      cache: false,
                      data: "put your data here",
                      success: function (response) {
                          alert("PostBack response " + response);
                      },
                      error: function () {
                          alert("PostBack Error");
                      }
                      });
                  }
                  and in your plugin (sorry it's in VB but the point is the same):

                  Code:
                  Public Overrides Function PostBackProc(page As String, data As String, user As String, userRights As Integer) As String
                  One gotcha is to make sure the page.html actually exists, even if you don't use it, or you'll get a 404 error - it doesn't have to be the page you're calling from.
                  Last edited by pseudocode; March 21, 2023, 12:00 PM. Reason: fixed code formatting

                  Comment


                    #10
                    Originally posted by pseudocode View Post
                    The example plugin shows how this can be done - basically in your JS:.
                    That is very close to what I am now trying to do in the databaseConfig.html page. Since I could not figure out how to grab the POST from the URL string sent to databaseReports.html I decided to try and send the POST data to the c# script then open the databaseReports.html page.

                    I'm getting closer (I think) but now I realized there is another issue... AjaxPost does not like "&" (the ampersand). Before I get much farther, I'm searching on how to encode it. Shouldn't be hard to find that info since it's probably a common problem.

                    Thanks for the suggestion!

                    Comment


                      #11
                      Finally figured it out. I cannot believe something as simple as the following code in databaseReports.html took me more than a week to figure out.

                      Code:
                      <script>
                        $( document).ready(function(){
                          const params = new URLSearchParams(window.location.search);
                          let scriptname = 'csUpdateIniFile.cs';
                          let fucn = 'csUpdateDatabaseIniFile';
                          let param = encodeURIComponent(params);
                          AjaxPost("action=run_script_command&scriptcommand=%26hs.runs criptfunc(%22" + scriptname + "%22%2C%22" + fucn + "%22%2C%22" + param + "%22%2CFalse%2CFalse)","runscript.html");
                        });
                      </script>​​

                      Comment

                      Working...
                      X