您的位置:首页 > Web前端 > JQuery

Jquery学习笔记之ajax

2011-03-31 21:11 447 查看
前几天一直都在了解xhtml+div+css 后来做出来的网页效果也不是很如意,但是总是算完成了作业。今天开始学jquery+ajax页面先后传值。

用户名:
密码 :
邮箱:
您还没有注册?next

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css">
-->
<mce:script type="text/javascript" src="jquery-1.4.min.js" mce_src="jquery-1.4.min.js"></mce:script>
<mce:script type="text/javascript"><!--
//jquery 你得这么写:
$(function(){
alert("ok?");
$(":input[type='button']").click(function(){
//传输数据 val()获得第一个匹配元素的当前值
var $param = "username="+$("#username").val()+"&password="+$("#password").val();
$.ajax({
url:'login.action',
data:$param,
type:'post',
dataType: 'json',
success :function(msg){
var o = eval(msg);//将json字符串转换成js对象
alert(o);
}
});
});

})

// --></mce:script>
</head>

<body>

用户名:<input name="username"  type="text" id="username"/><br>
密码 :<input name="password" type="password" id="password"><br>
邮箱:<input name="email"  type="text" id="email"/><br>
<input type="button" value="提交" id="submit"/>
<span>您还没有注册?</span><a href ="regist.jsp">next</a>
</body>
</html>


准备明天用jquery+ajax实现对页面的元素的操作。忘了,有一个问题没解决,怎么把msg返回到页面上显示出来,json对象是怎么遍历的了。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: