当前位置:网站首页>防止页面url缓存中 ajax中post 请求的处理方式
防止页面url缓存中 ajax中post 请求的处理方式
2022-07-19 14:47:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
一般我们在开发中经常会用到Ajax请求,异步发送请求,然后获取我们想要的数据,在Ajax中使用Get请求数据不会有页面缓存的问题,而使用POST请求可是有时候页面会缓存我们提交的信息,导致我们发送的异步请求不能正确的返回我们想要的数据,那么遇到这种情况,我们应该怎么办呢???
下面介绍一种方式来防止ajax中post 请求 页面缓存 url 信息:
$.post(url,data ,ranNum:Math.random()} ,function(data){
if("success"==data){
alert("success");
}else{
alert("error");
}
})
url : 请求的URL 地址
data : 请求的数据
ranNum : 这个是防止缓存的核心,每次发起请求都会用Math.random()方法生成一个随机的数字,这样子就会刷新url缓存
这个ranNum的生成方式有多种形式,你也可以按照自己的生成方式进行生成,只要确保生成数据的时候是随机的就好!这就是Ajax防止发送请求的时候防止url缓存的方法。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/121290.html原文链接:https://javaforall.cn
边栏推荐
- Google Chrome cannot be installed successfully after uninstallation
- Union and union all operators in SQL
- google chrome卸载之后无法安装成功
- A novel network training approach for open set image recognition
- 增强聚合,主题,数据仓库dwb,dws层降维,视频,review第1遍,220620,
- Import changes and enable auto import of idea
- 小程序云开发出坑系列(一)
- EasyExcel 使用Converter 转换注入时报nullPoint异常
- Roommates master binary tree while playing cloud top (super detailed)
- 11. 处理机调度的概念、层次
猜你喜欢
8. 进程
How can redis and MySQL data be consistent?
10. 线程
How does message middleware ensure 100% successful delivery of messages and idempotent design of messages
Learning Deep Classifiers Consistent With Fine-Grained Novelty DetectionCVPR2021开放集识别论文解读
为什么重写equals方法时必须重写hashCode方法
C2ae: class conditioned auto encoder for open set recognition cvpr2019 open set recognition paper interpretation
LeetCode78-子集详解
Generalized odin: Detecting out-of-distribution image without learning from out-of-distribution data
Conservative Novelty Synthesizing Network forMalware Recognition in an Open-Set Scenario
随机推荐
Generalized odin: Detecting out-of-distribution image without learning from out-of-distribution data
OpenGAN: Open-Set Recognition via Open Data Generation
Applet learning notes - Cloud Development
RTSP to H5 playback
Li Hongyi, machine learning 3 Gradient descent
promise
2018的锅让2019来悲
review第2遍,220614,视频,Day03_数据仓库设计,
JVM规范 oracle官网
review第1遍,220619,數據倉庫dwb層降維,視頻,
9.进程通信
Flex vertical layout elastic compression of applet
数据库查询优化
ThreadLocal的脏数据、内存泄露
OpenStack构建企业私有云-环境准备
Enhanced aggregation, theme, data warehouse DWB, DWS layer dimensionality reduction, video, review for the first time, 220620,
LeetCode78-子集详解
Review 1, 220619, Data Warehouse DWB Layer downsize, video,
Eureka强制下线服务
A novel network training approach for open set image recognition