Home Backend Development PHP Tutorial 请问jquery中的ajax如何只能发送一次数据,第二次发送如何无效

请问jquery中的ajax如何只能发送一次数据,第二次发送如何无效

Jun 13, 2016 pm 12:08 PM
ajax json location nbsp parent

请教jquery中的ajax怎么只能发送一次数据,第二次发送怎么无效?

本帖最后由 ziyou16036 于 2014-08-27 21:45:37 编辑 用jquery和ajax来异步刷新验证用户名和密码,可是怎么只能提交第一次有用呢?网上搜的方法我都试过了,可是没有用,到底该怎么办呢?我把代码贴出来给你们看看,希望高手可以解决!



$.ajax({
type:'POST',
    url:'=$baseUrl?>/public/logincheck',
    dataType:'json',
    data:{username:$("input[name='username']").val(),password:$("input[name='password']").val()},
    success: function(json){
if(json.message==4){
var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
parent.location.reload();//刷新父页面
parent.layer.close(index); //执行关闭
}else if(json.message==3){
addTip("用户名或密码不正确!");
       
}
    }
});  


我用的是zend framework框架做的项目,url地址中填写的是控制器的地址!


------解决思路----------------------
ajax本身看不出什么,你触发事件是什么?调试看看,第二次有没有触发此ajax方法
------解决思路----------------------
点击登录的地方,是否是绑定的click方法
------解决思路----------------------
$.ajax 应有 cache : false, 属性,否则服务端不阻止缓存时,至少IE不会刷新缓存数据

回调中,你有 parent.location.reload();//刷新父页面
自然自己也被刷新了
那么第二次发送是什么意思呢?
------解决思路----------------------
cache:false
------解决思路----------------------
在AJAX发送的URL后面,加上时间戳,确保每次发送的URL不一样
------解决思路----------------------
引用:
$.ajax 应有 cache : false, 属性,否则服务端不阻止缓存时,至少IE不会刷新缓存数据

回调中,你有 parent.location.reload();//刷新父页面
自然自己也被刷新了
那么第二次发送是什么意思呢?


同意此观点
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the 403 error encountered by jQuery AJAX request How to solve the 403 error encountered by jQuery AJAX request Feb 20, 2024 am 10:07 AM

How to solve the 403 error encountered by jQuery AJAX request

What is the difference between MySQL5.7 and MySQL8.0? What is the difference between MySQL5.7 and MySQL8.0? Feb 19, 2024 am 11:21 AM

What is the difference between MySQL5.7 and MySQL8.0?

Performance optimization tips for converting PHP arrays to JSON Performance optimization tips for converting PHP arrays to JSON May 04, 2024 pm 06:15 PM

Performance optimization tips for converting PHP arrays to JSON

How to solve jQuery AJAX request 403 error How to solve jQuery AJAX request 403 error Feb 19, 2024 pm 05:55 PM

How to solve jQuery AJAX request 403 error

How do annotations in the Jackson library control JSON serialization and deserialization? How do annotations in the Jackson library control JSON serialization and deserialization? May 06, 2024 pm 10:09 PM

How do annotations in the Jackson library control JSON serialization and deserialization?

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

How to get variables from PHP method using Ajax?

In-depth understanding of PHP: Implementation method of converting JSON Unicode to Chinese In-depth understanding of PHP: Implementation method of converting JSON Unicode to Chinese Mar 05, 2024 pm 02:48 PM

In-depth understanding of PHP: Implementation method of converting JSON Unicode to Chinese

How to solve the problem of jQuery AJAX error 403? How to solve the problem of jQuery AJAX error 403? Feb 23, 2024 pm 04:27 PM

How to solve the problem of jQuery AJAX error 403?

See all articles