简体   繁体   English

jQuery延迟对象回调不触发

[英]jquery deferred object callback not firing

I have the following code 我有以下代码

function get_hash(){
    id = $('#file_id').val()
    deferred =  $.ajax({ url: "/rest/hash_upload/", type: "GET", data: {file_id: id} })
    $.when(deferred).then(function(data){
        alert('executing')
        $('#input_md5_checksum').val(data)
    })
}

The ajax gets called and my backend returns the hash as expected. Ajax被调用,我的后端按预期返回哈希值。 However, the deferred callback method does not fire. 但是,延迟的回调方法不会触发。 Can anyone see what I'm doing wrong? 谁能看到我在做什么错?

Thanks. 谢谢。

Why set your query as a variable and and then use when() , why not just use a regular ajax call? 为什么将查询设置为变量,然后使用when() ,为什么不只使用常规的ajax调用呢?

        $.ajax({ 
            url: "/rest/hash_upload/", 
            type: "GET", 
            data: {file_id: id} 
        }).done(function(data){
            alert('executing');
            $('#input_md5_checksum').val(data);
        }).fail(function(xhr, status, error){
            return ("Ajax failed: " + xhr.responseText);
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM