• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
#define wzz
博客园    首页    新随笔    联系   管理    订阅  订阅
ajax接触
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;
					}
				}
			}
		});
		
	}

  

posted on 2015-12-17 10:36  #define wzz  阅读(158)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3