Ext.Ajax.request异步提交表单示例
服务器端代码:loginServer.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String userName=request.getParameter("username"); String password=request.getParameter("password"); String msg=""; //服务端程序根据用户输入的用户名和密码判断是否合法,如果输入正确就返回成功 if(userName.equals("11")&& password.equals("11")){ msg="登录成功"; }else{ msg="登录失败"; } response.getWriter().write(msg);//将登录信息写回客户端 %>
客户端代码:mylogin.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<title>Ext.Ajax.request异步提交表单示例</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">
-->
Ext.Ajax.request方式是客户端向服务端发送请求的重要方法。 调用格式: request(Object options): Object
Options:包含请求参数及回调处理参数,可能的属性:
url: String/Function (可选)。请求服务器地址
params: Object/String/Function(可选) 包含请求参数的配置对象
method:String (可选)。指定HTTP请求方式,有效包括GET和POST,默认使用 Ext.Ajax.request对象中method配置项的值。
callback:Function(可选)指定接收到服务器响应后的处理函数。