关于提交ajax表单的调用函数

时间:2012-08-20 19:54:08

标签: jquery ajaxform

我正在使用ajaxForm.js来上传ajax图片。

这是我使用的js函数:

$(document).ready(function() {
    $('#photoimg').live('change', function() {
        $("#hd_pic").html('');
        $("#loading").html('<img src="../img/common/loader.gif"/>').fadeIn(250);
        $("#imageform").ajaxForm({
            target: '#hd_pic'  
        }).submit();
    });
});

我不想将结果输出到目标:'#hd_pic',但我想调用一个函数。例如,我在我的ajax调用中这样做:

$.ajax({
    type: "POST",
    url: "/ajax/add_url.php",
    data: dataString,
}).done(function(result) {
    myresult(result);
});​

我调用函数myresult并使用ajax调用的结果。我也想在ajaxform提交函数中执行此操作。有可能这样做吗?

这不起作用:

        $("#imageform").ajaxForm({
        success: myresult(result)
    }).submit();

3 个答案:

答案 0 :(得分:0)

您可以使用成功回调属性代替目标,作为options之一:

$("#imageForm").ajaxForm({
    success: function() {
        // your callback code goes here
    }
});

答案 1 :(得分:0)

我认为你可以做到:

$("#imageform").ajaxForm({
    success: myresult
}).submit();

答案 2 :(得分:0)

您想要的确切语法

 $("#imageform").ajaxForm({
        target: '#hd_pic',
        success: function(){/*your code after here*/}
    })

jQuery API: Ajax Options

相关问题