javascript - ajax的绑定问题
本文介绍了javascript - ajax的绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
$('#find').click(function () {
$(document).ajaxStart(function () {
console.log("!!!!!!!!!!!!!!!1")
})
$(document).ajaxStop(function () {
console.log("!222222!!1")
})
$.getJSON("1.php",function (msg) {
})
})
为什么没有在console 输出任何字符呢?
还有ajax的绑定,这是什么意思呢?我点击我的按钮,然后我就发送ajax请求了,之后回调函数获得数据,这个绑定是干嘛的?
不好意思,没注意。。。我从webstorm里复制前面一段过来。
后面懒得复制了,就自己打上去,没注意。。。
还是没有任何输出呀?
$.getJSON("http://v.juhe.cn/weather/index?callback=?",function (msg) {
})
如果我请求一个api的话,就不能ajaxStart就不起作用了.
请求本地文件是起作用的,这个是为什么呢?
解决方案
你写的是
$('#find').click(function () {
$(document).ajaxStart(function () {
console.log("!!!!!!!!!!!!!!!1")
})
$(document).ajaxStop(function () {
console.log("!222222!!1")
})
$.getJSON("1.php",function (msg) {
}
})
我觉得应该是
$('#find').click(function() {
$(document).ajaxStart(function() {
console.log("!!!!!!!!!!!!!!!1")
})
$(document).ajaxStop(function() {
console.log("!222222!!1")
})
$.getJSON("1.php", function(msg) {
})
})
你看看有什么不同。。是不是发现少了一个右括号
这篇关于javascript - ajax的绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文