jquery寫的ajax

來源:互聯網
上載者:User

標籤:cell   out   ror   orm   highlight   ase   false   core   w3c   

1.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib prefix="s" uri="/struts-tags"%><%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 ‘Score.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"><script type="text/javascript" src="js/jquery.js"></script><link rel="stylesheet" type="text/css" href="css/table1.css">  </head>    <body>   <script type="text/javascript">function sub(){$.ajax({    url:‘Score.action?‘+Math.random(),    type:‘POST‘, //GET    async:true,    //或false,是否非同步    data:$(‘#form‘).serialize(),//提交表單資料    timeout:5000,    //逾時時間    dataType:‘json‘,    //返回的資料格式:json/xml/html/script/jsonp/text    beforeSend:function(xhr){        console.log(xhr);        console.log(‘發送前‘);    },    success:function(data,textStatus,jqXHR){$(‘#tb tr:not(:first)‘).remove();        for (var i = 0; i < data.length; i++) {        $(‘#tb‘).append(‘<tr><td>‘ + data[i].id.number + ‘</td><td>‘ + data[i].id.name + ‘</td><td>‘         + data[i].id.classs + ‘</td><td>‘ + data[i].id.course + ‘</td><td>‘ + data[i].id.score + ‘</td></tr>‘);        }                console.log(data);        console.log(textStatus);        console.log(jqXHR.responseText);    },    error:function(xhr,textStatus){        console.log(‘錯誤‘);        console.log(xhr);        console.log(textStatus);    },    complete:function(){        console.log(‘結束‘);    }});}  </script>    <form id="form" action="" >        <table>         <tr>        <th>課程<input name="course" id="course" type="text" size="10"></th>        <th>班級<input name="classs" id="classs" type="text"></th><th>學生學號<input type="text" id="number" name="number"></th> <th>學生姓名<input type="text" id="name" name="name"></th><th><input type="button" id="submit" value="查詢" onclick="sub()"></th>        </tr>        </table>        </form>              <table id="tb" cellpadding="4">       <tr>       <th>學號</th>       <th>姓名</th>       <th>班級</th>       <th>課程</th>       <th>成績</th>       </tr>              </table>          </body>   </html>

2.action(必須有set和get)

public String execute() throws Exception{if(classs.length()>0){if(course.length()>0){scorelist=mgr.findScoreByClassandCourse(classs, course);//一個班的某一科成績}else{scorelist=mgr.findScoreByClass(classs);//一個班的所有成績}}else if(number.length()>0){if(course.length()>0){scorelist=mgr.findScoreByNumberandCourse(number, course);//一個人的某一科成績}else{scorelist=mgr.findScoreByNumber(number);//一個人的所有成績}}else if(name.length()>0){if(course.length()>0){scorelist=mgr.findScoreByNumberandCourse(number, course);//一個人的某一科成績}else{scorelist=mgr.findScoreByName(name);//一個人的所有成績}}else if(course.length()>0){scorelist=mgr.findScoreByCourse(course);}else {scorelist.clear();}return SUCCESS;}

3.struts.xml

<package name="aaa" extends="json-default">

  

<action name="Score" class="ScoreAction"><result name="success" type="json"><param name="root">scorelist</param></result></action>

4.結果

 

jquery寫的ajax

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.