<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ajax-get().html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script language="JavaScript" src="jquery-1.6.1.js"></script>
<script language="JavaScript">
$(function(){
$("#bt1").click(function(){
var name =$("#tx1").val();
var URL = "../validate?name="+name+"&date="+new Date().getTime();
$.ajax({
type:"GET",
url:URL,
dataType:"xml",
success:function(msg){
alert(msg);
var jqueryObj =$(msg) ;//把后台传来的对象转为JQuery对象
alert(jqueryObj);
var content = jqueryObj.text();
$("#sp1").text(content);
}
});
})
})
</script>
</head>
<body>
<p align="center">
6-2 用户注册
</p>
<table align="center">
<tr>
<td>
用户名
</td>
<td>
<input type="text" id="tx1">
<input type="button" id="bt1" value="检测">
</td>
<td>
<span id="sp1"></span>
</td>
</tr>
</table>
</body>
</html>
后台服务器代码:
package com.wepull.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ValidateServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doProcess(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doProcess(request, response);
}
private void doProcess(HttpServletRequest request,
HttpServletResponse response) {
try {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
System.out.println("ajax传来的name:"+name);
name = URLDecoder.decode(name,"utf-8");
PrintWriter pw = response.getWriter();
if("w".equals(name)){
pw.println("<root>"+name+":已经被占用"+"</root>");
}else{
pw.println("<root>"+name+":可以注册"+"</root>");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
分享到:
相关推荐
asp+ajax(jQuery)实例($.ajax()、$.post()、$.get()、$.getJSON()四种模式可选 Ajax是目前比较流行的网站建设技术,尤其作为网站建设者来说,掌握它十分有必要,如果用原生Javascript开发则比较困难,还好有强大的...
详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
详细解读Jquery各Ajax函数: $.get(),$.post(),$.ajax(),$.getJSON() 一,$.get(url,[data],[callback]) 说明:url为请求地址,data为请求数据的列表,callback为请求成功后的回调函数,该函数接受两个参数,第一个...
主要介绍了详细解读Jquery各Ajax函数($.get(),$.post(),$.ajax(),$.getJSON())的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下
$.post、$.get是一些简单的方法,如果要处理复杂的逻辑,还是需要用到jQuery.ajax() 一、$.ajax的一般格式 $.ajax({ type: 'POST', url: url , data: data , success: success , dataType: dataType }); 二、...
NULL 博文链接:https://andy2019.iteye.com/blog/1515064
对于$.ajax请求来说,如果层级比较多,程序看起来会比较乱,而为了解决这种问题,才有了$when…done…fail…then的封装,它将$.ajax这嵌套结构转成了顺序平行的结果,向下面的$.ajax写法,看起来很乱 $.ajax({ url...
NULL 博文链接:https://xa-zbl.iteye.com/blog/552797
Jquery中$.getScript()$.getJSON()和$.ajax()的用法总结共4页.pdf.zip
一、前言 为什么需要用到同步,因为有时候我们给一个提交...type: 请求方式(post或get)默认为get。 timeout: 要求为Number类型的参数,设置请求超时时间(毫秒)。 async:默认设置为true,所有请求均为异步请求。同
注意:$.get()和$.post()方法是jQuery中的全局函数。前面讲到的load()方式是对jQuery对象进行操作的。 1、 $.get()方法 $.get()方法使用GET方式来进行异步请求。 它的语法结构为: $.get( url [, data] [, ...
jQuery的选择机制构建于Css的选择器,它提供了快速查询DOM文档中元素的能力,而且大大强化了JavaScript中获取页面元素的方式。
本文重点是来讲讲jQuery中调用ajax的4种方法:$.get、$.post、$getJSON、$ajax。如果读者没有javascript和jquery的知识,或者没有ajax的概念,那么请先去问问度娘,再来读本文。
本项目使用了jQuery的get/post两种方法提交Json格式的数据到后台,后台再把Json格式的数据传到前台。实现了JSON字符串和JSON对象之间的转换。
kefir-jquery-ajax 提出$ .ajax请求,退还开菲尔(kefir)属性! 安装 npm install kefir-jquery-ajax 用法示例 var kefirAjax = require ( 'kefir-jquery-ajax' ) //returns a promise for a GET to the query ...
$.post、$.get是一些简单的方法,如果要处理复杂的逻辑,还是需要用到jQuery.ajax() 一、$.ajax的一般格式 $.ajax({ type: 'POST', url: url , data: data , success: success , dataType: dataType }); 二、$...