【framework7中文文档】Framework7中DOM7库Ajax、Get、Post数据请求例子

时间:2020-11-14  来源:Dom教程  阅读:

1,Ajax请求
发送 Ajax 请求的代码格式如下:

$$.ajax(parameters)

方法里参数可选值如下:

 

 

 

 

使用样例:

$$(document).on("ajaxComplete", function (e) {
  var xhr = e.detail.xhr;
  console.log("request performed");
});

3,Get请求

虽然 Ajax 方法功能强大。但通常在项目中我们会更经常使用 Get 或 Post 方法,毕竟用起来方便很多。

Dom7.get 方法样例如下:


$$.get("blog-post.php", {foo:"bar", id:5}, function (data) {
  $$(".articles").html(data);
  console.log("Load was performed");
});

4,Post请求
Dom7.post 方法样例如下:

$$.post("auth.php", {username:"foo", password: "bar"}, function (data) {
  $$(".login").html(data);
  console.log("Load was performed");
});

5,异步获取JSON数据
使用 Dom7.getJSON 我们可以通过 ajax 的方式获取服务器上的 json 数据,并自动转换成对象。使用样例如下:

$$.getJSON("items.json", function (data) {
  console.log(data);
});

【framework7中文文档】Framework7中DOM7库Ajax、Get、Post数据请求例子

http://m.bbyears.com/wangyezhizuo/110398.html

推荐访问:framework7模板嵌套
相关阅读 猜你喜欢
本类排行 本类最新