JQuery简介

JQuery简介

Demo:

1..ajax请求-->Get

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#b01").click(function(){
  htmlobj=$.ajax({url:"/jquery/test1.txt",async:false});
  $("#myDiv").html(htmlobj.responseText);
  });
});
</script>
</head>
<body>

<div id="myDiv"><h2>通过 AJAX 改变文本</h2></div>
<button id="b01" type="button">改变内容</button>

</body>
</html>

2.Get请求:

<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $.get("/example/jquery/demo_test.asp",function(data,status){
      alert("数据:" + data + "\n状态:" + status);
    });
  });
});
</script>
</head>
<body>

<button>向页面发送 HTTP GET 请求,然后获得返回的结果</button>

</body>
</html>

3.Post请求:

<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $.post("/example/jquery/demo_test_post.asp",
    {
      name:"Donald Duck",
      city:"Duckburg"
    },
    function(data,status){
      alert("数据:" + data + "\n状态:" + status);
    });
  });
});
</script>
</head>
<body>

<button>向页面发送 HTTP POST 请求,并获得返回的结果</button>

</body>
</html>
<%
dim fname,city
fname=Request.Form("name")
city=Request.Form("city")
Response.Write("Dear " & fname & ". ")
Response.Write("Hope you live well in " & city & ".")
%>

4..ajax-->Get请求:

function Play(videoId){
	var videoName= $("#videoName").val();//将页面上id="videoName"的值拿过来
	$.ajax({
		type : "GET",
		url : "/video/getVideoPlayURL?videoId="+videoId+"&videoName="+videoName,
		dataType : "text", //json
		success : function(data) {
			var ret = eval(data);//data为controller返回的数据,将它转成ret对象
			$("#jishu").val(ret.jishu);//将ret对象中jishu值赋到id="jishu"中
		}});
    }
	<a href="javascript:void(0)" onclick="Play(${video.id})">Ajax请求</a>
	
	a.dataType:"text"
		String videoURL = "ajax返回的字符串";
		return "@" + videoURL;

	b.dataType:"json"
		Map<String,Object> urlMap = new HashMap<String,Object>();
		urlMap.put("jishu", newjishu);
		urlMap.put("url", videoURL);
		String result = JSONObject.fromObject(urlMap).toString();
		return "@" + result;

http://www.w3school.com.cn/jquery/

相关推荐