ajax基础知识,ajax基础知识

ajax基础知识:

Asynchronous JavaScript and xml

进行局部更新

实现方式(常用的):

1.$.ajax();

2.$.get();

3.$.post();

1.$.ajax()

url:进行数据交换的url

type:请求方式

data:提交的参数

success:成功后回调该方法,可用于接收并处理传回的结果

error:失败后回调该方法

dataType:设置接收到的响应体的数据格式

2..get(),.get(),.get(),.post()

url,[data],[callback],[type] String,Map,Function,String

url:待载入页面的URL地址

data:待发送 Key/value 参数。

callback:载入成功时回调函数。

type:返回内容格式,xml, html, script, json, text, _default

举例:

servletDemo:

package ServletDemo;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

@WebServlet("/servletDemo")

public class servletDemo extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

doPost(request, response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

try {

Thread.currentThread().sleep(5000);

} catch (InterruptedException e) {

e.printStackTrace();

}

response.getWriter().write(request.getParameter("username")+" is you ?");

}

}

xxx.html

Insert title here

/*

$("#send").click(function () {

$.ajax({

url:"http://localhost:8080/TryAjax/servletDemo",

type:"POST",

data:{"username":"LiMi",

"age":23,

"location":"GuangDong"},

success:function(data){

alert(data);

},

dataType:"text"

});

})

*/

/*

$("#send").click(function () {

$.get("http://localhost:8080/TryAjax/servletDemo",

{"username":"LiMi","age":23,"location":"GuangDong"},

function (data) {

alert(data);

},

"text"

);

})

Request URL:http://localhost:8080/TryAjax/servletDemo?username=LiMi&age=23&location=GuangDong

Request Method:GET

Status Code:200

Remote Address:[::1]:8080

Referrer Policy:no-referrer-when-downgrade

*/

$("#send").click(function () {

$.post("http://localhost:8080/TryAjax/servletDemo",

{"username":"LiMi","age":23,"location":"GuangDong"},

function (data) {

alert(data);

},

"text"

);

})

/*

Request URL:http://localhost:8080/TryAjax/servletDemo

Request Method:POST

Status Code:200

Remote Address:[::1]:8080

Referrer Policy:no-referrer-when-downgrade

Response Headers

*/

标签:function,8080,servletDemo,基础知识,ajax,import,http,data

来源: https://blog.csdn.net/whyfive4/article/details/100638244

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值