-
ajax进不了后台action5
jsp页面代码:login.jsp
<%@ page language="java" pageEncoding="GBK" contentType="text/html; charset=GBK"%> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%> <%@ page import="com.trustmo.system.common.constants.CommonConstants" %> <%@ page import="javax.servlet.http.Cookie"%> <%@ page import="com.trustmo.utils.time.TimeUtils" %> <% String path = request.getContextPath(); response.setHeader( "Pragma", "No-cache" ); response.setHeader( "Cache-Control", "no-cache" ); response.setDateHeader( "Expires", 0 ); %> <html> <head> <title>四川移动集中日志审计平台登陆</title> <link type="text/css" href="<%=path%>/css/index.css" rel="stylesheet" /> <link type="text/css" href="<%=path%>/css/common.css" rel="stylesheet" /> <script language="javascript" src="<%=path%>/js/common.js"></script> <script language="javascript" src="<%=path%>/js/prototype.js"></script> <script language="javascript" src="<%=path%>/js/buffalo.js"></script> </head> <% String userName = ""; String userPsw = ""; Cookie[] cookies = null; cookies = request.getCookies(); if( cookies != null ){ for( int i = 0; i < cookies.length; i++ ){ if( cookies[i].getName().equals( "loginUser" ) ){ userName = cookies[i].getValue(); } if( cookies[i].getName().equals( "loginPsw" ) ){ userPsw = cookies[i].getValue(); } } } %> <script language="javascript"> var isAuthCode='<%=CommonConstants.COMMON_YES_STRING%>'; //焦点获取 function init(){ self.name='login'; var Obj=document.getElementById("userEntity.userName"); Obj.focus(); } /****登录验证****/ function login(){ var msg=""; if(document.forms[0].elements['userEntity.userName'].value==""){ msg+="请输入登录名称!"; alert(msg); return false; } if(document.forms[0].elements['userEntity.userPwd'].value==""){ msg+="请输入登录密码!"; alert(msg); return false; } if(document.forms[0].elements['userEntity.isAuthCode'].value=='<%=CommonConstants.COMMON_YES_STRING%>'){ if(document.forms[0].elements['code'].value==""){ msg+="请输入验证码!"; alert(msg); return false; } } var winWidth=screen.availWidth-10; var winHeight=screen.availHeight-40; document.forms[0].action="login.do?method=login"; var param = "toolbar=no,width="+ winWidth +",height="+ winHeight +",top=0,left=0,scrollbars=yes,resizable=yes,center:yes,statusbars=yes"; <%-- window.open("about:blank","index",param); --%> <%-- document.forms[0].target="index";--%> document.forms[0].target="login"; document.forms[0].submit(); <%-- window.opener=null;--%> <%-- window.close();--%> } function loginenter(){ if(13==event.keyCode){ login(); } } function setPswCheck(){ <% if(!userPsw.trim().equals("")){ %> document.forms[0].elements['pswCheckBox'].checked=true; <% } %> } function getIsAuthCode(){ var userName = document.forms[0].elements['userEntity.userName'].value; if(trim(userName) != "") { check(userName); } } /** * 使用buffalo验证查询 */ var endPoint = "<%=request.getContextPath()%>/bfapp"; var buffalo = new Buffalo(endPoint); function check(userName){ buffalo.remoteCall("systemCheckUserName.checkUserName", [userName], function(reply){ var msg = reply.getResult(); if( msg == '<%=CommonConstants.COMMON_USER_ISAUTHCODE_YES%>' ){ document.forms[0].elements['userEntity.isAuthCode'].value=msg; document.getElementById("code_div").style.color=""; document.getElementById("authCode").readOnly=false; document.getElementById("codehref").href="javascript:getCode();"; document.getElementById("codehref").style.color=""; return; } else if( msg == '<%=CommonConstants.COMMON_USER_ISAUTHCODE_NO%>' ){ document.forms[0].elements['userEntity.isAuthCode'].value=msg; document.getElementById("code_div").style.color="#AAAAAA"; document.getElementById("authCode").disabled=true; document.getElementById("codehref").href="javascript:getCode();"; document.getElementById("codehref").style.color="#AAAAAA"; return; } else{ alert( msg ); } }); } function getCode(){ var userName = document.forms[0].elements['userEntity.userName'].value; if(trim(userName)!=""){ doRequestUsingPOST(userName); } } function doRequestUsingPOST(userName){ createXMLHttpRequest(); var url="<%=path%>/login.do?method=generateCode"; xmlHttp.open("POST", url, true); var queryString = "userName=" + userName; xmlHttp.onreadystatechange = handleStateCode; xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); xmlHttp.send(queryString); } function createXMLHttpRequest(){ if (window.ActiveXObject){ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest){ xmlHttp = new XMLHttpRequest(); } } function handleStateCode(){ if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200){ var text = xmlHttp.responseText; if( trim(text) == '<%=CommonConstants.COMMON_USER_ISAUTHCODE_YES%>'){ alert("验证码已成功发送您的手机上!"); }else{ alert(text); } } } } </script> <style type="text/css"> html,body{ margin:0; font-family:"宋体"; height:100%; color:#1A1A1A; font-size:14px; background:#E0F3FB;} .input1{ width:140px; height=20px; background:#FFFFFF; border:1px solid #6C6C6C;} .font1{ font-size:12px; color:#3F3F3F} </style> <body onload="self.name='login'; init(); setPswCheck();show_action_message();" onkeypress="loginenter();"> <html:form action="login.do" method="post"> <html:hidden name="loginForm" property="userEntity.isAuthCode" /> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#E1F1F7"> <tr> <td> <table width="538" height="387" border="0" cellpadding="0" cellspacing="0" background="<%=path%>/images/login_bg.jpg" align="center"> <tr> <td valign="top" style="padding-top:165px;"> <table width="300" border="0" align="center" cellpadding="1" cellspacing="0"> <tr> <td width="220"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="30"> 用户名:<html:text name="loginForm" property="userEntity.userName" styleClass="input1" value="<%=userName%>" onchange="getIsAuthCode();" /> </td> </tr> <tr> <td height="30"> 密 码:<html:password name="loginForm" property="userEntity.userPwd" styleClass="input1" value="<%=userPsw%>" /> </td> </tr> <tr> <td height="30"> <div id="code_div"> 验证码:<html:text name="loginForm" property="code" size="4" styleId="authCode" style="height=20px; background:#FFFFFF; border:1px solid #6C6C6C;" /> <a href="javascript:getCode();" id="codehref" name="codehref">获取短信验证码</a> </div> </td> </tr> <tr> <td height="20" class="font1"> <input type="checkbox" name="userNameCheckBox" checked="checked" />记住用户名 <input type="checkbox" name="pswCheckBox" />记住密码 </td> </tr> </table> </td> <td style="cursor:hand;" valign="top"> <img id="login_image" src="<%=path%>/images/login.gif" onmouseover="login_focus('login_image')" onmouseout="login_moveOut('login_image')" onclick="login()" width="66" height="68" border="0" /> </td> </tr> </table> <table width="74%" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top:25px;"> <tr> <td align="right" class="font1"> 相关法律|四川移动公司所有 @2009 </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </html:form> <jsp:include page="/common/action_exception.jsp"></jsp:include> </body> </html>
java代码:LoginAction.javapackage com.trustmo.system.action; import java.io.Writer; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DispatchAction; import com.trustmo.system.biz.LogBiz; import com.trustmo.system.biz.UserBiz; import com.trustmo.system.common.cache.UserCache; import com.trustmo.system.common.constants.CommonConstants; import com.trustmo.system.entity.LogEntity; import com.trustmo.system.entity.UserEntity; import com.trustmo.system.message.SendUserLogCode; import com.trustmo.utils.exception.ActionException; import com.trustmo.utils.exception.ExceptionUtil; import com.trustmo.utils.time.TimeUtils; public class LoginAction extends DispatchAction { private static Logger logger = LogManager.getLogger(LoginAction.class); /** * 用户登录 * * @return */ public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { logger.info("用户登录"); UserBiz userBiz = new UserBiz(); LoginForm loginForm = (LoginForm) form; try { UserEntity userEntityNew = loginForm.getUserEntity(); // 从页面获取用户名、用户密码 // String userNameCheckBox = loginForm.getUserNameCheckBox(); // 是否记住用户名 // String pswCheckBox = loginForm.getPswCheckBox(); // 是否记住密码 // 非管理员登陆,校验验证码 // if( userEntityNew.getIsAuthCode() == CommonConstants.COMMON_YES_INT ){ // String msg = validateCode( request, loginForm.getCode() ); // request.getSession().setAttribute( "code", "" );// 清除已过期的验证码 // if( !msg.trim().equals( "" ) ){ // throw new ActionException( msg ); // } // } // 用户登陆 UserEntity userEntity = userBiz.login(null, userEntityNew); // 设置cookie // CookieUtil.updateCookie( response, request, cookieName, // cookieValue ); // userEntityNew.setLogIp( request.getRemoteAddr() );// // 获取用户登陆IP地址:其他模块记录系统操作日志用 // 记录日志 LogEntity logEntity = new LogEntity(); logEntity.setLogNo(TimeUtils.getstrNo()); logEntity.setLogType(CommonConstants.COMMON_USER_LOG_LOGIN_KEY); logEntity.setLogOrgNo(userEntity.getOrgNo()); logEntity.setLogUsername(userEntity.getUserName()); logEntity.setLogUserChinesName(userEntity.getUserChineseName()); logEntity.setLogTime(TimeUtils.getDateStr()); logEntity.setLogIp(request.getRemoteAddr()); logEntity.setLogRemark(""); if (userEntity != null) { logEntity.setMsg("用户登录成功:登录名:" + userEntity.getUserName() + ",登录时间:" + logEntity.getLogTime()); // 当前用户存入Session中 request.getSession().setAttribute(CommonConstants.COMMON_SESSION_USER_KEY, userEntity); // 当前用户存入页面form loginForm.setUserEntity(userEntity); } else { logEntity.setMsg("用户登录失败:登录名:" + userEntityNew.getUserName() + ",登录时间:" + logEntity.getLogTime()); } new LogBiz().insertLogEntity(null, userEntity, logEntity); } catch (ActionException ex) { // 固定格式:在页面上弹出的内容存储到request中,供页面调用 request.setAttribute(ExceptionUtil.errors_message, ExceptionUtil.getBusiness_ActionError(ex)); logger.warn("自定义异常:" + ex.getMessage()); return mapping.findForward("failed"); } catch (Exception e) { // 固定格式:在页面上弹出的内容存储到request中,供页面调用 request.setAttribute(ExceptionUtil.errors_message, ExceptionUtil.getSystem_ActionError()); logger.fatal("系统异常:", e); return mapping.findForward(ExceptionUtil.system_exception_forward); } return mapping.findForward("success"); } /** * 用户注销 * * @return */ public ActionForward logout(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try { // 获取用户信息 UserEntity userEntity = (UserEntity) request.getSession().getAttribute(CommonConstants.COMMON_SESSION_USER_KEY); if (userEntity == null) { return mapping.findForward("failed"); } // 注销session request.getSession().setAttribute(CommonConstants.COMMON_SESSION_USER_KEY, null); } catch (Exception e) { // 固定格式:在页面上弹出的内容存储到request中,供页面调用 request.setAttribute(ExceptionUtil.errors_message, ExceptionUtil.getSystem_ActionError()); logger.fatal("系统异常:", e); return mapping.findForward(ExceptionUtil.system_exception_forward); } return mapping.findForward("failed");// 注销成功 } /** * 获取验证码 * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward generateCode(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { logger.info("开始生成验证码并发送到用户手机上!"); response.setContentType( "text/html;charset=GBK" ); // 设置响应的编码方式 Writer out = response.getWriter(); // 取得输出 String userName = request.getParameter("userName"); // 取得用户名 LoginForm loginForm = ( LoginForm )form; try { String msg =""; if ( !userName.equals(CommonConstants.COMMON_ADMINISTATOR_USERNO_KEY) ) { UserEntity userEntity = UserCache.getUserEntityByUserName(userName); // 根据用户名取得相对应的实体 if ( null == userEntity ) { msg = "用户" + userName + "不存在"; } else if ( "".equals(userEntity.getMobile().trim()) ){ msg = "手机号码不存在!请与管理员联系!"; } else if( "".equals(msg) ){ String str = "" + userEntity.getIsAuthCode(); if ( str.equals(CommonConstants.COMMON_USER_ISAUTHCODE_NO) ){ // 判断是否需要使用验证码 msg = CommonConstants.COMMON_USER_ISAUTHCODE_NO; } else { msg = CommonConstants.COMMON_USER_ISAUTHCODE_YES; String code = SendUserLogCode.start( userEntity.getMobile() ); // 得到验证码,发送短信 userEntity.setUserName( userName ); request.getSession().setAttribute( "code", "" ); // 将code的session置空 request.getSession().setAttribute( "codeTime", "" ); // 将code的session置空 request.getSession().setAttribute( "code", code ); // 将验证码code存入session中 request.getSession().setAttribute( "codeTime", TimeUtils.getDateStr() ); // 将创建Code的时间存入session中 loginForm.setUserEntity( userEntity ); // userEntity放入页面form } } if( !"".equals(msg) ){ out.write(msg); // 设置输出信息 out.flush(); // 向客户端输出 if( out != null ){ out.close(); // 关闭输出流 } return null; } } else { msg = CommonConstants.COMMON_USER_ISAUTHCODE_NO; out.write(msg); // 设置输出信息 out.flush(); // 向客户端输出 if( out != null ){ out.close(); // 关闭输出流 } } }catch(Exception e){ // 固定格式:在页面上弹出的内容存储到request中,供页面调用 request.setAttribute(ExceptionUtil.errors_message, ExceptionUtil.getSystem_ActionError()); logger.fatal("系统异常:", e); return mapping.findForward(ExceptionUtil.system_exception_forward); } return null; } }
xml代码:struts-config.xml<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config> <data-sources /> <form-beans> <form-bean name="loginForm" type="com.trustmo.system.action.LoginForm"></form-bean> </form-beans> <global-exceptions /> <global-forwards> <forward name="systemException" path="/common/exception.jsp" /> </global-forwards> <action-mappings> <!-- 登陆Action --> <action attribute="loginForm" input="/login.jsp" validate="false" name="loginForm" parameter="method" path="/login" scope="request" type="com.trustmo.system.action.LoginAction"> <forward name="failed" path="/login.jsp" /> <forward name="success" path="/index.jsp" /> </action> </action-mappings> <message-resources parameter="com.trustmo.system.ApplicationResources" /> </struts-config>
web.xml<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <!-- 默认页面 --> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> <!-- 设置session失效时间 --> <session-config> <session-timeout>30</session-timeout> </session-config> <!-- 日志初始化 --> <servlet> <servlet-name>log4j-init</servlet-name> <servlet-class>com.trustmo.utils.log4j.Log4jInit</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <!-- 缓存初始化 --> <servlet> <servlet-name>CacheInit</servlet-name> <servlet-class>com.trustmo.utils.cache.CacheInit</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <!-- 读取配置文件 --> <servlet> <servlet-name>action</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> <init-param> <param-name>config</param-name> <param-value> /WEB-INF/struts-config.xml, /WEB-INF/struts_configs/struts-system-config.xml, /WEB-INF/terminal/approval/struts-terminal-approval-config.xml, /WEB-INF/terminal/fireWall/struts-terminal-fireWall-config.xml, /WEB-INF/terminal/fireWallEmergency/struts-terminal-fireWallUrgent-config.xml, /WEB-INF/terminal/fortress/struts-terminal-fortress-config.xml, /WEB-INF/terminal/inquire/struts-terminal-inquire-config.xml, /WEB-INF/terminal/superAccount/struts-terminal-superAccount-config.xml, /WEB-INF/terminal/usb/struts-terminal-usb-config.xml, /WEB-INF/terminal/vpn/struts-terminal-vpn-config.xml, /WEB-INF/terminal/vpnEmergency/struts-terminal-vpnUrgent-config.xml, /WEB-INF/terminal/basis/struts-terminal-basis-config.xml, /WEB-INF/terminal/applicationsrecord/struts-terminal-record-config.xml, /WEB-INF/terminal/auditflow/struts-terminal-auditflow-config.xml, /WEB-INF/terminal/appobject/struts-terminal-appobject-config.xml </param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>3</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>3</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- 菜单Servlet --> <servlet> <servlet-name>MenuServlet</servlet-name> <servlet-class> com.trustmo.system.common.tools.MenuServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>MenuServlet</servlet-name> <url-pattern>/menuServlet</url-pattern> </servlet-mapping> <!-- 页面编码 --> <filter> <filter-name>characterEncoding</filter-name> <filter-class> com.trustmo.system.common.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>GBK</param-value> </init-param> <init-param> <param-name>ignore</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncoding</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>characterEncoding</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>characterEncoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 登录验证 --> <filter> <filter-name>userAuthorization</filter-name> <filter-class> com.trustmo.system.common.filter.UserAuthorizationFilter </filter-class> </filter> <filter-mapping> <filter-name>userAuthorization</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>userAuthorization</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <!--buffalo框架引用--> <servlet> <servlet-name>bfapp</servlet-name> <servlet-class>net.buffalo.web.servlet.ApplicationServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>bfapp</servlet-name> <url-pattern>/bfapp/*</url-pattern> </servlet-mapping> </web-app>
现在问题就在于
var url="<%=path%>/login.do?method=generateCode";
xmlHttp.open("POST", url, true);
未能进入到action中,没有执行generateCode方法;
做调试时,当把方法名换成了login时,能进入login方法;另一种情况是当登录后,再在当前页面打开login.jsp页面,此时能进入action并执行generateCode方法;此类问题只出现在login.jsp这个页面和LoginAction.java这个action中。
就像是login.jsp只识别LoginAction.java中的login方法,即使重新写了一个action也是不行的!
其他地方做的ajax验证或者超链都可以进入后台的action中。
求各位大大帮忙解答疑惑,问题是出在什么地方,怎么解决才能进入action中执行generateCode方法,Thank you!!2011年11月11日 10:55
相关推荐
本篇文章将深入探讨jQuery如何与后台进行Ajax交互。 ### 1. jQuery中的Ajax函数 jQuery提供了一个名为`$.ajax()`的全局函数,用于发起Ajax请求。这个函数支持多种HTTP请求方法,如GET、POST、PUT、DELETE等。基本...
《Ajax实战(Ajax in action中文版)》一书深入浅出地介绍了这一技术,旨在帮助开发者熟练掌握Ajax的核心概念和实践应用。 **1. Ajax基础** Ajax的基础在于JavaScript,XMLHttpRequest对象是实现Ajax的核心。这个对象...
AJAX(Asynchronous JavaScript and XML)的核心是通过JavaScript在后台与服务器进行少量数据交换,无需重新加载整个网页。 在ASP.NET中,我们通常创建一个WebMethod或使用ASP.NET MVC的ActionResult来作为AJAX的...
1. **渐进增强**:确保即使在不支持Ajax的浏览器中,网站也能正常工作。 2. **避免阻塞UI**:使用异步请求,确保用户界面的流畅性。 3. **优化性能**:减少HTTP请求次数,合并资源,使用缓存等手段提高加载速度。 ...
**Ajax in Action(代码篇)** Ajax,全称Asynchronous JavaScript and XML,是一种在无需刷新整个网页的情况下,能够更新部分网页的技术。它通过在后台与服务器进行少量数据交换,使网页实现异步更新。在"Ajax in ...
Ajax,全称Asynchronous JavaScript and XML(异步JavaScript和XML),是一种创建交互式网页应用的技术,通过在后台与服务器进行少量数据交换,实现了网页的局部刷新,极大地提升了用户体验。 本书内容涵盖了Ajax...
在本文中,我们将深入探讨如何使用jQuery Progressbar与Ajax相结合,来实时展示后台处理任务的进度,特别是在一个基于Struts2框架的应用中。这个过程包括前端的jQuery Progressbar组件的设置,以及后端如何发送进度...
**Ajax Struts 无刷新访问后台返回JSON数据详解** 在Web开发中,为了提供更流畅、高效的用户体验,无刷新(Ajax)技术被广泛应用于页面更新。结合Struts框架,我们可以实现后端服务与前端交互,返回JSON数据,使得...
11. **Progressive Enhancement**:书中可能强调渐进增强的开发策略,确保即使在不支持AJAX的浏览器中,网站也能正常工作。 12. **AJAX应用实例**:书中会通过实例讲解如何将这些技术应用于实际项目,如实时搜索、...
Ajax允许我们在不刷新整个页面的情况下与服务器交换数据并更新部分网页内容。这里,我们使用jQuery的`$.ajax()`方法,将图片的坐标或状态信息以JSON格式发送到后台: ```javascript $.ajax({ url: 'struts2Action....
1. 异步通信:Ajax的关键特性是它允许浏览器与服务器之间进行非同步数据交换,这意味着用户可以继续浏览页面,而后台则在处理请求。 2. JavaScript:Ajax主要由JavaScript驱动,通过创建XMLHttpRequest对象来发起...
Ajax(Asynchronous JavaScript and XML)是一种用于创建快速响应的Web应用的技术组合,它通过在后台与服务器进行少量数据交换,使网页可以实现局部刷新,而无需重新加载整个页面。这极大地提升了用户体验,使得Web...
**Ajax实战(Ajax in Action)** Ajax,全称Asynchronous JavaScript and XML,是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术。本书《Ajax实战》深入浅出地讲解了如何利用Ajax技术来构建高性能、...
标题中的"AJAX In Action(中文版) .pdf"表明这是一个关于AJAX技术的中文教程。AJAX(Asynchronous JavaScript and XML)是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术。它通过在后台与服务器进行...
Ajax,即异步JavaScript和XML,允许我们在不刷新整个页面的情况下与服务器进行通信。jQuery提供了$.ajax()函数来实现这一功能,它可以发送一个HTTP请求到服务器并处理响应。在获取后台数据生成下拉框的场景中,我们...
在Web开发中,AJAX(Asynchronous JavaScript and XML)是一种技术,它允许我们在不刷新整个页面的情况下与服务器进行异步数据交换。而Struts2是一个基于MVC(Model-View-Controller)架构的Java Web框架,它极大地...
下面通过三个具体例子来详细讲解如何使用jQuery发起Ajax请求,并处理后台返回的数据。 ### 示例一:投票功能实现 **HTML结构** ```html (1)">投票 ``` **JavaScript代码** ```javascript function vote(id) { ...
1. **XMLHttpRequest对象**:这是Ajax的核心,用于在后台与服务器进行通信。JavaScript通过创建XMLHttpRequest实例,发送HTTP请求并处理响应。 2. **JavaScript函数**:创建和管理Ajax请求的代码通常写在JavaScript...
总结,Ajax在Action这本书中文版的《Ajax实战》中,将深入探讨这些概念和技术,包括如何在实际项目中有效利用Ajax提升Web应用程序的性能和用户体验。通过阅读本书,开发者可以掌握Ajax的精髓,从而在实践中游刃有余...