jQuery$.post()在Android WebView中不起作用
我正在尝试从Android调用JavaScript,但jQuery$.post()在Android WebView中不起作用,android,jquery,webview,http-post,Android,Jquery,Webview,Http Post,我正在尝试从Android调用JavaScript,但$.post()不起作用。我在《邮递员》杂志上试过了,效果不错 o/p:未定义输出 MainActivity.java newhtml.html 函数loadjs(){ 控制台日志(“调用”); var json_config={ 名称:“唐老鸭”, 城市:“Duckburg” }; log(“name”+json_config.name); log(“城市”+json_config.city) $.post(”http://www.w3s
$.post()
不起作用。我在《邮递员》杂志上试过了,效果不错
o/p:未定义输出MainActivity.java newhtml.html
函数loadjs(){
控制台日志(“调用”);
var json_config={
名称:“唐老鸭”,
城市:“Duckburg”
};
log(“name”+json_config.name);
log(“城市”+json_config.city)
$.post(”http://www.w3schools.com/jquery/demo_test_post.asp,json_配置,函数(数据,状态){
控制台日志(“数据”+数据);
控制台日志(“状态”+状态);
}).失败(功能(响应){
log(“输出为”+response.responseText)
});
}
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()");
}
});
<!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>