在ajax表单中不调用Success函数


Success function is not called in ajax form

$('#upload').on('click',function(){
$('#upload_form').ajaxForm({
    url:insert_url,
    type:'post',
    target:'#preview',
    beforeSubmit:function(e){
        console.log('before');
        $('.progress').show();
    },
    success:function(res, status, xhr, form){
        console.log('che');
        $('.progress').hide();
    },
    error:function(e){
        console.log('error');
    }
}).submit();

我有一个帖子形式,但我想知道如何获得成功功能的工作,如果我的照片上传。函数似乎根本没有被调用。

您是否使用jQuery表单插件?如果是这样,请确保它是添加到HTML中的源代码,并且加载时没有错误。

你的代码看起来不完整,是因为你在$('#upload').on('click',function(){里面有其他的东西吗?如果没有,请确保关闭该函数,这就是我的意思(我还修复了缩进):

$('#upload').on('click', function() {
    $('#upload_form').ajaxForm({
        url: insert_url,
        type: 'post',
        target: '#preview',
        beforeSubmit: function(e) {
            console.log('before');
            $('.progress').show();
        },
        success: function(res, status, xhr, form) {
            console.log('che');
            $('.progress').hide();
        },
        error: function(e) {
            console.log('error');
        }
    }).submit();
});

还要确保在此代码之前定义了insert_url

如果仍然不工作,控制台是否显示"before","che"或"error"?