ajax接触
2015-12-17 10:36
246 查看
1. function doSave() { ajax_get("${contextPath}/auth/functionsave", $("#editForm").serialize(), function(data) { if (data.errorMessage) { showmsg(0, data.errorMessage); } else { showmsg(1, "处理成功!"); } }); } 2.跳出窗口 funFrame.location.href="${contextPath}/auth/functionform?id="+treeNode.id; 3. ffunction ajaxFileUpload(id) { var uploadUrl = encodeURI(encodeURI("${contextPath}/commons/uploadimgs")); if (uploadUrl != "") { $.ajaxFileUpload({ url : uploadUrl, secureuri : false, fileElementId : 'uploadfile' + id, dataType : 'text', success : function(data, status) { var dataset = jQuery.parseJSON(jQuery(data).text()); if (dataset.ret == "ok") { if (id == 0) { $("#sicon").attr("src", dataset.url); $("#icon").val(dataset.url); //alert(1); } else if (id == 1) { $("#smicon").attr("src", dataset.url); $("#micon").val(dataset.url); } else if (id == 2) { $("#sbicon").attr("src", dataset.url); $("#bicon").val(dataset.url); } } else if (dataset.ret == "empty") { showmsg(0, '没有选择图片,请先选择图片!'); } else { shomsg(0, '图片上传失败,请重试!!'); } }, error : function(data, status, e) { console.log(e); console.log(data); showmsg(0, '图片上传失败,请重试!!'); } }); } } 4. $.ajax({ url : "${contextPath}/web/createproject1.htm", data : $("#editForm").serialize(), cache : false, success : function(xmlHttp) { var res = xmlHttp; if (res.errorMessage && res.errorMessage != "") { showmsg(0, res.errorMessage); } else { location.href = "${contextPath}/web/tocreateproject2.htm?projectid="+ res.llong; } } }); 4.ajax 动态传值 (同一个页面中) <a href="#" onclick="getRightInfo(${v.ctid})"></a> <div id="rightinfo"></div> <script type="text/javascript"> $(document).ready(function() { }); function getRightInfo(ctid) { $.ajax({ url : "${contextPath}/web/infoshoplist.htm", data : "ctid="+ctid, cache : false, success : getRightInfoCallback }); } function getRightInfoCallback(xmlHttp) { var mainfloor = xmlHttp.infoshoplist; if (mainfloor != null) { $("#rightinfo").hide(); var str = ''; for (var i = 0; i < mainfloor.length; i++) { str += '<a href="${contextPath}/web/infoshop.htm?shopid=' + mainfloor[i].shopid + '">'; str += '<div class="media">'; str += '<div class="A">'; str += '<div class="media-left">'; str += '<img class="media-object" src="${contextPath}/resources/' + mainfloor[i].icon + '">'; str += '</div>'; str += '<div class="media-body">'; str += '姓名:'+ mainfloor[i].username; str += '<br>'; str += '标签:'+ mainfloor[i].ctname; str += '<br>'; str += '店铺:'+ mainfloor[i].shopname; str += '</div>'; str += '</div>'; str += '</div>'; str += '</a>'; } $("#rightinfo").html(str); $("#rightinfo").show(); } else { $("#rightinfo").hide(); } } </script> @RequestMapping("/infoshoplist.htm") @ResponseBody public Map<String, Object> infoshoplist(Model model, RequestParameter param) { Map<String, Object> map = new HashMap<String, Object>(); map.put("infoshoplist", webService.getInfoShopList(param.getCtid())); return map; } 5. function doLogin() { if (trim($('#username').val()) == "") { showmsg(0, "请输入用户名"); return; } if (trim($('#password').val()) == "") { showmsg(0, "请输入密码"); return; } $.ajax({ url : "${contextPath}/web/login.htm", data : $("#loginForm").serialize() , cache : false, success : function(xmlHttp) { var res = xmlHttp; if (res.errorMessage && res.errorMessage != "") { showmsg(0, res.errorMessage); } else { if (str_isblank(res.status)) { showmsg(1, "登录成功!"); window.setTimeout("window.location='${contextPath}/web/toindex.htm'", 1500); } else { showmsg(1, "登录成功!"); var fromUrl = res.status; location.href = fromUrl; } } } }); }
相关文章推荐
- java中的集合链表
- hadoop中有时运行会提示mapper找不到
- MapReduce-求最高温度
- 修改Ubuntu的aptget源为阿里源的方法
- 使用 coocox 编写 stm32 代码 (过程、问题) 归纳
- ztree 展示
- IT工程师值得一看的书籍
- python unicode字符串
- 解决python安装selenium报错问题ImportError: No module named 'selenium'
- 用C#实现实现简单的 Ping 的功能,用于测试网络是否已经联通
- iOS代码布局适配(系统的方法两种)
- http以post方式上传一个文件,构造其请求头和消息报文 application/x-www-form-urlencoded multipart/form-data
- ios、java之间的RSA加解密
- 无聊的吐槽
- ztree edit_super
- Raphael的Braille例子
- 转:pyqt实例
- ViewFlipper 实现幻灯片功能
- 经典灰鸽子lcx上线大全
- MySQL基础安全注意细节