Ajax -- $.get() 方法解析 JSON 数据
来源:互联网 发布:mac chrome收费? 编辑:程序博客网 时间:2024/05/21 00:52
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><script type="text/javascript" src="script/jquery-1.7.2.js"></script><script type="text/javascript">function RandomString(length) { var str = ''; for ( ; str.length < length; str += Math.random().toString(36).substr(2) ); return str.substr(0, length); } $(function(){ $("#btn02").click(function(){ //$.get(URL,data,success(response,status,xhr),dataType); $.get("AjaxJqueryGetServlet",{userName:'Jerry',passWord:'Jerry12345',date:RandomString(32)},function(data,status,xhr){ alert("后台返回数据: " + data.userName + ", " + data.passWord); alert("状态: " + status); alert("数据类型:" + xht); },"json"); }); });</script></head><body> <center> <button id="btn01">$.post() 方法解析 JSON 数据</button><br/> <button id="btn02">$.get() 方法解析 JSON 数据</button> </center></body></html>
package com.atguigu.ajax.servlet;import java.io.IOException;import java.io.PrintWriter;import java.util.HashMap;import java.util.Map;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 com.google.gson.Gson;@WebServlet("/AjaxJqueryGetServlet")public class AjaxJqueryGetServlet extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Map<String,String> map = new HashMap<>(); String userName = request.getParameter("userName"); String passWord = request.getParameter("passWord"); map.put("userName", userName); map.put("passWord", passWord); Gson gson = new Gson(); String gsonMap = gson.toJson(map); PrintWriter out = response.getWriter(); out.write(gsonMap); }}
阅读全文
0 0
- Ajax -- $.get() 方法解析 JSON 数据
- jQuery.get方法请求JSON数据,解析JSON数据 注意事项
- ajax解析Json数据的方法
- Ajax -- $.post() 方法解析 JSON 数据
- ajax 提交post get 数据,得到json结果解析
- ajax解析JSON数据
- 12306模拟get方法 ——json解析数据
- Jquery ajax方法解析返回的json数据
- Jquery ajax方法解析返回的json数据
- Jquery ajax方法解析返回的json数据
- Jquery ajax方法解析返回的json数据
- JSON数据解析方法
- JSon数据解析方法
- Json数据解析方法
- knock.js的subscribe使用 通过$.ajax(); $get();解析JSON数据
- Ajax与jQuery-利用$.get()和$.post()方法传递html,xml,json数据
- Ajax与jQuery-利用$.get()和$.post()方法传递html,xml,json数据
- $.ajax方法(传递json数据)
- 对外接口如何保证安全
- 设计模式之单例模式Singleton
- iOS百思不得姐、ARKit、旋转动画、立体相册源码等
- 大前端时代来临,我们何去何从?
- 分页的工具类
- Ajax -- $.get() 方法解析 JSON 数据
- 精华【分布式、微服务、云架构dubbo+zookeeper+springmvc+mybatis+shiro+redis】分布式大型互联网企业架构!
- 欧拉函数辱骂你 2333333333
- 【poj 2104】K-th Number【整体二分+树状数组】
- c++ string char* char[]之间的转化
- Eclipse项目转移到IntelliJ IDEA
- 2017最新PHP经典面试题目汇总(上篇)
- 将excel导入sql数据库 id自增长
- MyEclipse 7.5注册码