[JQuery]如何使用POST/GET
[JQuery]如何使用POST/GET
Post:
$(function(){ var responseMsg = $('#responseMsg'); responseMsg.html(''); $('#loginBt').click(function(){ var username = $('#username').val(); var password = $('#password').val(); var url = "login.do"; $.post(url, {account:username,password:password}, function(data, status){ console.log('data: ' + data) if(data.description == 'Success'){ var strFullPath=window.document.location.href; var strPath=window.document.location.pathname; var pos=strFullPath.indexOf(strPath); var prePath=strFullPath.substring(0,pos); var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1); window.location.href=prePath + postPath + '/page/home.html'; } else { responseMsg.html('Invalid username or password'); } }) }) });
Get:
var url = "login.do?username="+username+"&password="+password; $.get(url, function(data, status){ if(data.description == 'Success'){ var strFullPath=window.document.location.href; var strPath=window.document.location.pathname; var pos=strFullPath.indexOf(strPath); var prePath=strFullPath.substring(0,pos); var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1); window.location.href=prePath + postPath + '/page/home.html'; } else { responseMsg.html('Invalid username or password'); } })
ajax post:
$.ajax({ url : url, beforeSend : function(){ ajaxLoading(); }, type : 'POST', data : { submit_time_from : submitTimeFrom, submit_time_to : submitTimeTo, corp_id : corpId, }, success : function(data, status){ ajaxLoadEnd(); if(data == 'Please login first'){ responseMsg.html(data); return; } var statusCode = data.code; if (statusCode == '0') { responseMsg.html(data.description); } else { responseMsg.html(data.description); } } });
function ajaxLoading(){ $("
").css({display:"block",width:"100%",height:$(window).height()}).appendTo("body"); $("").html("Being handling, please wait...").appendTo("body").css({display:"block",left:($(document.body).outerWidth(true) - 190) / 2,top:($(window).height() - 45) / 2}); } function ajaxLoadEnd(){ $(".datagrid-mask").remove(); $(".datagrid-mask-msg").remove(); }版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~