2

Followed this, though Ajax calls from link executes without any errors, having below function in a HTML fails still

$(document).ready(function() {
       alert("Ready");
       $.ajax({
           url: "https://www.google.com/",
           type: 'GET',
           cache: false,
           data: "{'name':'hi'}",
           contentType: 'application/json',
           dataType: 'json',
           async: true,
           success: function(res) {
             alert('success res-:' + JSON.stringify(res));
           },
           error: function(res) {
             alert('error res-:' + JSON.stringify(res));
           }
        });

Update Java Code

   import javafx.application.Application;
   import javafx.scene.Scene;
   import javafx.scene.control.ButtonType;
   import javafx.scene.control.Dialog;
   import javafx.scene.web.WebView;
   import javafx.stage.Stage;
   import netscape.javascript.JSObject;

   public class FXWebViewSO extends Application  {

    public static void main(String[] args) {
    launch(args);
    }

    public void start(Stage primaryStage) {
    primaryStage.setTitle("JavaFX WebView Example");

    WebView webView = new WebView();
    webView.getEngine().setJavaScriptEnabled(true);
    webView.getEngine().setOnAlert(event -> showAlert(event.getData()));
    webView.getEngine().setJavaScriptEnabled(true);
    JSObject window = (JSObject) webView.getEngine().executeScript("window");
    window.setMember("window", null);

//  webView.getEngine().load("file://webview.html"); // Fails - HTML having above Ajax function
    webView.getEngine().load("http://www.jquerysample.com/#BasicAJAX"); // Works

    final Scene scene = new Scene(webView);
    primaryStage.setScene(scene);
    primaryStage.show();
    }

    private void showAlert(String message) {
    System.out.println(message);
    Dialog<Void> alert = new Dialog<>();
    alert.getDialogPane().setContentText(message);
    alert.getDialogPane().getButtonTypes().add(ButtonType.OK);
    alert.showAndWait();
    }
   }

Note: The same works fine in couple of windows machines and failes from Ubuntu Desktop.

Environment details below

Ubuntu - 1.8.0_151 - Failed (Tried upgrading too still no luck).

Windows7 - 1.8.0_221 - Works

Samy
  • 2,387
  • 2
  • 17
  • 31
  • (just a simple case), Are you using the same browser(version as well) on both OS? (it should not be the OS-specific as far as I know) – Shekhar Rai Jan 27 '20 at 12:09
  • Does version of browser really matters as i am launching the html in JavaFX Webview? – Samy Jan 27 '20 at 13:09
  • Have you provided an alert handler to the WebView engine as recommended by the updated answer in the question you linked? – jewelsea Jan 29 '20 at 09:40
  • Java 8 is old now, a more modern library is Java 13+ with JavaFX 13+. I don't have a version of Ubuntu installed to try out your sample with a more modern JavaFX version to see if it would work. You might wish to try that. If the issue remains platform specific on a new JavaFX version, then [file a bug report](https://wiki.openjdk.java.net/display/OpenJFX/Submitting+a+Bug+Report). – jewelsea Jan 29 '20 at 09:43
  • @jewelsea Yes alert handlers are in place. The same works on a very few windows machine, whereas fails majority in Ubuntu. We are working on qualifying our application in Java13+. Let me update my question with the Java portion too. – Samy Jan 29 '20 at 10:09

0 Answers0