Buonasera a tutti,
ho un problema con la webview e codice jquery.
Nella webview devo fare un submit di un form e devo leggere il risultato, per fare questo utilizzo jquery con ajax ma l'ultino risultato che ottengo e' la chiamata fallito al file php che chiamo. allego un progetto di esempio
CODICE B4J
contenuto file TEST-CONNESSIONE.PHP
ho un problema con la webview e codice jquery.
Nella webview devo fare un submit di un form e devo leggere il risultato, per fare questo utilizzo jquery con ajax ma l'ultino risultato che ottengo e' la chiamata fallito al file php che chiamo. allego un progetto di esempio
CODICE 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
contenuto file TEST-CONNESSIONE.PHP
B4X:
<?php
echo "Chiamata avvenuta correttamente";
?>
Attachments
Last edited: