B4J Question Webview dont work with jquery

FabioRome

Member
Licensed User
Longtime User
connection failed to test-connessione.php

code b4j

B4X:
Dim we,wvjo As JavaObject
    we.InitializeNewInstance("javafx.scene.web.WebEngine",Null)
    wvjo = WebView1
    we = wvjo.RunMethod("getEngine",Null)
    Dim useragent As String=$"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"$
    we.RunMethod("setUserAgent",Array(useragent))

    Dim s As StringBuilder
    s.Initialize
    s.Append($"
    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
      $("#bottone").click(function(){
        var nome = $("#nome").val();
        var siteURL = "https://www.my-website.com/";
        $.ajax({
          type: "POST",
          url: "test-connessione.php",
          data: "nome=" + nome ,
          dataType: "html",
          success: function(msg)
          {
              $("#risultato").html(msg);
          },
          error: function()
          {
              $("#risultato").html(msg);
    //        alert("Chiamata fallita, si prega di riprovare...");
          }
        });
      });
    });
    </script>
    </head>
    <body>
    <form id="modulo" name="modulo">
        <p>Nome</p>
        <p><input type="text" name="nome" id="nome">
        <input type="button" id="bottone" value="Invia i dati">
    </form>
    <div id="risultato"></div>
    </body>
    </html>
    "$)
    Dim startPage As String = s
    WebView1.Loadhtml(startPage)

Sub WebView1_MouseClicked (EventData As MouseEvent)
    Dim joWV As JavaObject = WebView1
    Try
        joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", _
        Array As String("document.getElementById('modulo').click();"))
    Catch
        Log(LastException.Message)
    End Try
End Sub

TEST-CONNESSIONE.PHP
B4X:
<?php
echo "Chiamata avvenuta correttamente";
?>
 

Attachments

  • testWebView.zip
    2.6 KB · Views: 211

FabioRome

Member
Licensed User
Longtime User
google translate: webview does the batch submit of a parameter on an external internet page and shows the result in the webview
 
Upvote 0

FabioRome

Member
Licensed User
Longtime User
google translate: I do not have to make an insert in a database, but a submit of an external page that sends a confirmation after entering. What I'm writing is a software that puts it in a webnewsletter (phplist) with the DOUBLE OPT-IN method
 
Upvote 0

miker2069

Active Member
Licensed User
Longtime User
Instead of embedding the html/query code in the app itself, why not put it in a .html file on your server and use WebView1.LoadUrl to load it. See if that works. I haven't used jquery/ajax in a while but I believe the source of the page making the jquery requests and the target of the request needs to be on the same web server.
 
Upvote 0
Top