jQuery $ .post()在Android WebView中不起作用

时间:2016-09-06 10:30:06

标签: android jquery webview http-post

我正在尝试从Android调用JavaScript,但$.post()无效。我在Postman中尝试过它并且它正在工作。

  

o / p:输出未定义

MainActivity.java

    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("file:///android_asset/newhtml.html");
    webView.setWebViewClient(new WebViewClient(){
        @Override
        public void onPageFinished(WebView view, String url) {
            webView.loadUrl("javascript:loadjs()");
        }
    });

newhtml.html

<!Doctye HTML>
<html>
<head>
  <title></title>
  <script src="jquery.min.js"></script>
  <script type="text/javascript">
    function loadjs(){
        console.log("called");
        var json_config = {
                name: "Donald Duck",
                city: "Duckburg"
            };
        console.log("name "+json_config.name);
        console.log("city "+json_config.city)

         $.post("http://www.w3schools.com/jquery/demo_test_post.asp",json_config,function(data,status){

            console.log("data "+data);
            console.log("status "+status);
        }).fail(function(response) {
             console.log("output is "+response.responseText)
        });
    }
</script>
</head>
<Body>
<div id="print_host"></div>
</Body>
</html>

0 个答案:

没有答案