您当前的位置: 首页 >  彭世瑜 Java

Javascript:jQuery的ajax请求get请求模板

彭世瑜 发布时间:2018-09-07 15:57:10 ,浏览量:6

确保引入jQuery可用 https://code.jquery.com/jquery-3.3.1.min.js


ajax方式
$.ajax({
	type: "GET",
	url: "/json",
	dataType: "json",
	success: function (data) {
		// do something;
	}
});

如果请求到的是json对象,不需要反序列化,可以直接操作

get方式
$.get(url,data,success(response,status,xhr),dataType)

// 等价于
$.ajax({
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

示例

$.get(
	"test.cgi", 
	{ name: "John", time: "2pm" },
	function(data){
    alert("Data Loaded: " + data);
  });
POST方式
$.post(url,data,success(data, textStatus, jqXHR),dataType)

// 等价于
$.ajax({
  type: 'POST',
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

参考:

  1. $.ajax()方法详解
  2. jQuery ajax - get() 方法
关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 6浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0790s