问题描述
寻求帮助,哪位大侠可以帮忙给以ajax的例子和query的例子,详细点最好,在哪里可以查找到关于这两个的好资料!
解决方案
给你个ajax的例子,不过是用struts2写的package com.neusoft.etp.action;import java.io.PrintWriter;import java.util.List;import javax.servlet.http.HttpServletResponse;import org.apache.struts2.ServletActionContext;import com.neusoft.etp.bizservice.CheckSubjectBS;import com.neusoft.etp.domain.Tknowledge;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;/** * <pre>[描述信息:说明类的基本功能]</pre> * * @author 王川 - wang.chuan@neusoft.com * @version 1.0 Created on May 31, 2012 5:49:19 PM */public class ShowWebTextAC extends ActionSupport {private static final long serialVersionUID = 1L; private Tknowledge tknowledge;public Tknowledge getTknowledge() {return tknowledge;}public void setTknowledge(Tknowledge tknowledge) {this.tknowledge = tknowledge;}public String findBySub() { try { HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); List<String> list = checkSubjectBS.findBySub(tknowledge.getSubjecttype()); out.print(list); out.flush(); out.close(); } catch (Exception e) { System.out.println("异常信息:" + e); } return null; }}<html> <head> <title><s:property value="title" /></title> <script type="text/javascript"> var xmlHttp ; var flag = false ; function createXMLHttp(){ if(window.XMLHttpRequest){ xmlHttp = new XMLHttpRequest() ; } else { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") ; } } function findBySub(){ createXMLHttp(); var obj=document.getElementById("tpapers.subjecttype"); xmlHttp.open("POST","etp/showTextAC.action",true); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8"); xmlHttp.onreadystatechange = findBySubCallback ; xmlHttp.send("tknowledge.subjecttype="+obj.value); } function findBySubCallback(){ var sel=document.getElementById("tpapers.knowledge"); if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200){ var text =xmlHttp.responseText; var arr=new Array(); var str=text.substring(1,text.length-1) ; arr=str.split(", "); for(var j=0;j<arr.length;j++){ sel.options.add(new Option(arr[j], arr[j])); } } } } </script> </head> <body> <h3>XmlHttp ajaxDemo</h3> <br /> Subject:<input type="text" id="tpapers.subjecttype" /> <button onclick="findBySub()">Ajaxsubmit</button><br /><br /> Knowledge:<select id="tpapers.knowledge" style="width:150"></select></body></html>这是我最近写的,我有很多例子,你要是想要的话,把你邮箱给我,我可以发给你
解决方案二:
jquery官方文档比较权威http://api.jquery.com/category/ajax/
解决方案三:
jquery: http://docs.jquery.com/Main_Pagejquery ajax: http://api.jquery.com/jQuery.ajax/
解决方案四:
网上随便搜搜 很多的,W3CSCHOOL的或者其他的 http://www.w3school.com.cn/jquery/jquery_ajax.asphttp://www.ibm.com/developerworks/cn/xml/x-ajaxjquery.html