栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

jquery对AJAX的支持

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

jquery对AJAX的支持

语法:

$.ajax(参数);

参数是json格式

{

type: “GET或POST”,

url : “请求的服务器地址”,

data:“仅限于POST提交数据k1=v1&k2=v2…kn=vn”,

success:function(responseText){做事}

}

<%@ page language="java" pageEncoding="UTF-8" %>
<%
   String path = request.getContextPath ( );
   String basePath = request.getScheme ( ) + "://" + request.getServerName ( ) + ":" + request.getServerPort ( ) + path + "/";
%>



  
   ajax
  
  
  
  
  
  
  
  



   用户名:
  

   密码:




改造成POST提交

(1)服务端

package com.njwbhz.mood.servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet ( "/checkUserName.do" )
public class CheckUserNameServlet extends HttpServlet {
   @Override
   protected void doPost ( HttpServletRequest request , HttpServletResponse response ) throws ServletException, IOException {
      this.doGet ( request , response );
   }
   @Override
   protected void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException, IOException {
      String result = "";//相应的结果数据
      String userName = request.getParameter ( "userName" );
      //模拟 假设数据库中存在用户名“sa”
      if ( userName.equals ( "sa" ) ) {
         //不可用
         result = "0";
      } else {
         //可用
         result = "1";
      }
      //把result数据响应回去
      //发送到(写到)客户端浏览器
      //流
      PrintWriter out = response.getWriter ( );
      out.write ( result );
      out.flush ( );
      out.close ( );
   }
}

(2)客户端

<%@ page language="java" pageEncoding="UTF-8" %>
<%
   String path = request.getContextPath ( );
   String basePath = request.getScheme ( ) + "://" + request.getServerName ( ) + ":" + request.getServerPort ( ) + path + "/";
%>



  
   ajax
  
  
  
  
  
  
  
  



   用户名:
  

   密码:




 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/970103.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号