Fetch请求后台的数据
<style>
#btn{
width: 50px;
height: 50px;
background-color: red;
}
#output{
width: 100px;
height: 100px;
background-color: pink;
}
</style> <button id="btn"></button>
<div id="output"></div>
//jsong格式数据
//js代码
<script>
btn.onclick=function(){
fetch("data.json",{
headers:{
"Content-Type":"application/json"
},
}).then(function(res){
return res.json();
}).then(function(data){
console.log(data);
var str="";
data.forEach(item => {
str+=`<p>${item.name}<p>` });
document.getElementById("output").innerHTML=str; }).catch(error=>console.log(error))
}
</script>
/* Fetch发送请求 get*/
var page=1;
var pageSize=5;
var totalPage=0;
fetch(`/user/queryUser?page=${page}&pageSize=${pageSize}`, { headers: {
'Content-Type': 'application/json; charset=UTF-8'
}, }).then(res => res.json()).then(res => {
console.log(res);
totalPage=(Math.ceil(res.total/pageSize));
var html = template("userTpl", res);
console.log(html);
$("#userBox").html(html);
}).catch(err => {
console.log(err);
})
//Fetch请求 post
Fetch请求后台的数据的更多相关文章
- 一、表单和ajax中的post请求&&后台获取数据方法
一.表单和ajax中的post请求&&后台获取数据方法 最近要做后台数据接收,因为前台传来的数据太过于混乱,所以总结了一下前台数据post请求方法,顺便写了下相对应的后台接收方法. 前 ...
- 【11】ajax请求后台接口数据与返回值处理js写法
$.ajax({ url: "/test.php",//后台提供的接口 type: "post", //请求方式是post data:{"type ...
- AFN请求后台返回数据为NSInlineData类型的处理
在利用AFN进行数据解析时出现返回数据为 <7b227374 61747573 223a302c 226d6573 73616765 223a22e6 82a8e79a 84e6898b e69 ...
- echarts 中 请求后台改变数据
function tablenumber() { $.ajax({ type : "get", url : "../res/error.json", dataT ...
- node后台fetch请求数据-Hostname/IP doesn't match certificate's altnames解决方法
一.问题背景 基于express框架,node后台fetch请求数据,报错Hostname/IP doesn't match certificate's altnames..... require(' ...
- Swift - 后台获取数据(Background Fetch)的实现
前面讲了如何让程序申请后台短时运行.但这个额外延长的时间毕竟有限.所以从iOS7起又引入两种在后台运行任务的方式:后台获取和后台通知. 1,后台获取介绍 后台获取(Background Fetch)是 ...
- 前后端数据交互(四)——fetch 请求详解
fetch 是 XMLHttpRequest 的升级版,使用js脚本发出网络请求,但是与 XMLHttpRequest 不同的是,fetch 方式使用 Promise,相比 XMLHttpReques ...
- js页面用定时任务通过AJAX获取后台数据,但是从这个页面跳转到其他页面后,定时任务仍然在定时请求后台
setInterval(function(){//ajax 请求后台数据},1000);这个是A页面的定时器然后我在A页面通过其他请求跳转到其他页面之后后台发现A页面的定时器的那个请求仍然在执行为什么 ...
- React native 中使用Fetch请求数据
一.代码 import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View } from ' ...
随机推荐
- [转]Raw Queries in Laravel
本文转自:https://fideloper.com/laravel-raw-queries Business logic is often complicated. Because of this, ...
- C# WPF 获取窗体和控件的句柄
窗体: IntPtr hwnd = new WindowInteropHelper(this).Handle; 控件: IntPtr hwnd = ((HwndSource)PresentationS ...
- Spring Day 1
概述 开发三层架构,web层 service服务层,dao持久层. web层struts2配置核心过滤器/*,通过拦截器调用目标action,action中调用service层开启事务. servic ...
- asp.net-基础-20180320
常用页面指令 <%@page%>:一个页面只能有一个 <%@Import NameSpace=“Value“%> 导入命名空间 <%@OutputCache%> 设 ...
- SQL 語法
查詢 Sql = ("SELECT A1, A2, A5, A4 FROM Table1 ") 筆數 Sql = ("Select COUNT(*) From TW01. ...
- [android] sharedPreference入门
/********************2016年5月6日 更新**************************************/ 知乎:Android 如何实现判断用户首次使用,比如首 ...
- 5.QT-QString类
Qt中的字符串类 介绍 采用Unicode编码 采用隐式共享技术,节省内存和不必要的数据拷贝 隐式共享介于浅拷贝和深拷贝之间,当两个string对象赋值时,会实现浅拷贝(共享一块内存),如果某个对象 ...
- 面试官:你分析过mybatis工作原理吗?
Mybatis工作原理也是面试的一大考点,必须要对其非常清晰,这样才能怼回去.本文建立在Spring+SpringMVC+Mybatis整合的项目之上. 我将其工作原理分为六个部分: 读取核心配置文件 ...
- phpstudy 产生You don't have permission to access / on this server.解决
phpstudy配置好访问目录时候有时候会产生You don't have permission to access / on this server. 解决办法: 修改服务器httpd.conf配置 ...
- spring boot 集成 redis lettuce
一.简介 spring boot框架中已经集成了redis,在1.x.x的版本时默认使用的jedis客户端,现在是2.x.x版本默认使用的lettuce客户端,两种客户端的区别如下 # Jedis和L ...