AndroidToastForJs aj;
aj = new AndroidToastForJs(WebViewActivity.this, webview);
webview.addJavascriptInterface(aj, "AppNativeInterface");//JS交互
public class AndroidToastForJs {
private Context mContext;
private comdgdfg.example.android.mcworld.WebViewNoScroll mWebView;
// 初始化方法
public AndroidToastForJs(Context context, comdgdfg.example.android.mcworld.WebViewNoScroll myweb) {
this.mContext = context;
this.mWebView = myweb;
}
/**
* 用于前端自己跳转h5页面方法
* url:加载的网址
* titleText:标题名称
* titleType:标题栏显示类型
* */
@JavascriptInterface
public void toAppHTML() {
Toast.makeText(mContext,"调通了",Toast.LENGTH_LONG).show();
}
}
getData = function(uid) {
alert(uid);
AppNativeInterface.toAppHTML();
$.ajax({
url:"http://192.168.1.169:9543/auth/login",
data:JSON.stringify({
username:"liangtou",
password:"admin"
}),
type:"POST",
contentType: "application/json; charset=utf-8",
dataType:"json", //返回数据的类型
success:function(re){
console.log(re); //在console中查看数据
alert('success!');
},
error:function(re){
alert(JSON.stringify(re));
},
});
}