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就不起作用了.

请求本地文件是起作用的,这个是为什么呢?

阅读 2.5k
3 个回答

你写的是

$('#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) {
    
    })
})

你看看有什么不同。。是不是发现少了一个右括号

.ajaxstart()是在发送ajax请求之前执行的方法,.ajaxstop()当然就是在请求完成后执行的方法

$.getJSON("1.php",function (msg) {
        })

getJson后面少个括号。。。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题