- 爱易网页
-
JavaSript
- easyui form表单提交 路径有关问题
日期:2014-05-16 浏览次数:20417 次
easyui form表单提交 路径问题
js代码:
var submitForm;
//js获取项目根路径,如: http://localhost:8088/jquery
function getRootPath(){
//获取当前网址,如: http://localhost:8088/jquery/easyui/login.jsp
var curWwwPath = window.document.location.href;
//获取主机地址之后的目录,如: jquery/easyui/login.jsp
var pathName = window.document.location.pathname;
var pos = curWwwPath.indexOf(pathName);
//获取主机地址,如: http://localhost:8088
var localhostPaht = curWwwPath.substring(0, pos);
//获取带"/"的项目名,如:/jquery
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
return (localhostPaht + projectName);
}
/**
* 页面加载完后加载
*/
$(function(){
var form = $('#loginForm').form();
submitForm = $('#loginForm').form({
url: getRootPath()+'/login',
onSubmit:function(){
return $(this).form('validate');
},
success: function(msg){
if (msg == "success") {
alert("登录成功!!!");
}
else {
alert("登录失败!!!");
}
}
});
$('#dd').dialog({
//模态窗口
//modal: true,
//确定和取消按钮
height: '180',
closable: false,
buttons: [{
text: '登录',
iconCls: 'icon-ok',
//按钮事件方法
handler: function(){
submitForm.submit();
//$('#loginForm').submit();
}
}]
});
submitForm.find('input').on('keyup',function(event){
if(event.keyCode==13){
submitForm.submit();
}
});
});
这样写完后提交路径本应该是
localhost:8088/jquery/easyui/login?uname=1&upass=11111&prepass=11111
就对了,但实际路径变成localhost:8088/jquery/easyui/login.jsp?uname=1&upass=11111&prepass=11111,导致不能进入后台,因为form的url: getRootPath()+'/login' 为 localhost:8088/jquery/easyui/login