rururu2211785113的博客通过本文主要向大家介绍了ajax请求 angularjs-ht等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
1.ajax请求:
mui.plusReady(function() { var self = plus.webview.currentWebview(); for(var i = 0; i < 5; i++) { var temp = {}; var sub = plus.webview.create(subpages[i], subpages[i], subpage_style); if(i > 0) { sub.hide(); } else { temp[subpages[i]] = "true"; mui.extend(aniShow, temp); } self.append(sub); } plus.runtime.getProperty(plus.runtime.appid, function(inf) { wgtVer = inf.version; var _config = { url: 'http://60.30.254.100:8035/' // url: 'http://192.168.1.108:8080/' } var checkUrl = _config.url + "version/compareVersionIndexMain.action"; var data = { "appversion": wgtVer, "id": "3" } $.ajax({ type: "POST", url: checkUrl, dataType: "json", data: { ds: JSON.stringify(data) }, success: function(data) { if(data.success == "0"){ alert("已有新版本,请更新"); }else if(data.success == "1"){ } }, error: function(e) { return; } }); }); });
注意:
第一点:plus-api代码要写在plus-ready之后
第二点:ajax请求要用JSON.stringify转一下,返回的数据data.success是String数据,与0或者1比较要用==
java后台代码:
@RequestMapping("/compareVersionIndexMain") public void compareVersionIndexMain(HttpServletRequest req, HttpServletResponse res) throws UnsupportedEncodingException { req.setCharacterEncoding("utf-8"); System.out.println("AAAAAAAAAAAA"); String ds = req.getParameter("ds"); System.out.println("ds==="+ds); JSONObject json = JSONObject.fromObject(ds); System.out.println("解析后的json数据===" + json.toString()); String appversion = json.getString("appversion"); String id = json.getString("id"); JSONObject jsonObject = new JSONObject(); if (id != null && appversion != null) { Version version = dao.getVersionById(Integer.parseInt(id)); if (Float.parseFloat(appversion) < Float.parseFloat(version .getV_num())) { jsonObject.put("success", "0"); jsonObject.put("url", version.getUrl()); } else { jsonObject.put("success", "1"); } } else { jsonObject.put("success", "-1"); } System.out.println("首页检查更新返回的数据==="+jsonObject.toString()); returnResponse(res, jsonObject.toString()); }
第三点:plus-ready和plus-api位置,链接: MUI -- plus初始化原理及plus is not defined,mui is not defined 错误汇总
服务器如何接收前台传送的json数据,链接:Java后台如何接收并处理前台传过来的json格式的数组参数
ajax请求如何处理服务器返回的json数据,链接:jquery的ajax异步请求接收返回json数据
2.angular js使用http请求:
<html ng-app="mine_main">
<body class="mui-fullscreen" ng-controller="LSControllerForMineMain">
ng-model---变量名
ng-app---整体
ng-controller---控制器
ng-init---初始化
var app = angular.module('mine_main', []); app.controller('LSControllerForMineMain', function($scope, $location, $http) { //alert(JSON.parse(localStorage.getItem("userInfo")).realname); $scope.realname = localStorage.getItem("realname"); $scope.data = null; var wgtVer = null; $http({ method: 'POST', url: LSHelper.getInstance().getValue('baseurl') + '/respection_problems/getRoleName.action', header: { 'Content-Type': 'application/x-www-form-urlencoded', 'Cookie': LSHelper.getInstance().getValue('sessionid') } }).then(function successCallback(response) { //alert(JSON.stringify(response)); if(response.data.success == 1) { $scope.roleName = response.data.data; } else { alert("error,code:" + response.data.success); } }, function errorCallback(response) { alert("error"); }); $scope.updateVersion = function() { // alert("更新版本"); // 获取本地应用资源版本号 plus.runtime.getProperty(plus.runtime.appid, function(inf) { wgtVer = inf.version; // alert("当前应用版本:" + wgtVer); }); if(wgtVer != null) { var _config = { url: 'http://60.30.254.100:8035/' // url: 'http://192.168.1.108:8080/' } var checkUrl = _config.url + "version/compareVersion.action" plus.nativeUI.showWaiting("检测