在提交表单之前触发java脚本

时间:2014-03-06 16:41:08

标签: javascript jquery

你好,在创建我的php脚本时,我遇到了执行脚本1 [ajax uploader]的难度(来自提交)。触发上传的代码是uploadObj.startUpload();我尝试在提交操作之前将其添加到脚本2上,但不知何故它不会午餐。你能救我吗?

脚本1。

var uploadObj = $("#mulitplefileuploader").uploadFile({
    url: "uploader/upload.php",
    multiple: false,
    fileName: "myfile",
    maxFileSize: 655360 * 100, //5mb
    allowedTypes: "jpg,png,gif,zip,txt,doc,docx,csv,xml,pdf,JPG,JPEG,jpeg",
    maxFileCount: 1,
    autoSubmit: false,
    dragDropStr: "<span><b>Przeciągnij i upuść plik</b></span>",
    abortStr: "Anuluj",
    cancelStr: "Przerwij",
    doneStr: "Dodano",
    dynamicFormData: function () {
        var data = {
            uid: "<?PHP echo $_SESSION['userid']; ?>"
        }
        return data;
    },
    onSubmit: function (files) {
        $("#eventsmessage").html($("#eventsmessage").html() + "<br/>Submitting:" + JSON.stringify(files));
    },
    onSuccess: function (files, data, xhr) {
        $("#eventsmessage").html($("#eventsmessage").html() + "<br/>Success for: " + JSON.stringify(data));

    },
    afterUploadAll: function () {
        $("#eventsmessage").html($("#eventsmessage").html() + "<br/>All files are uploaded");

    },
    onError: function (files, status, errMsg) {
        $("#eventsmessage").html($("#eventsmessage").html() + "<br/>Error for: " + JSON.stringify(files));
    }
});

脚本2。

$(document).ready(function () {
    var options = {
        target: "#msgholder",
        beforeSubmit: function () {
            showLoader;
        },
        success: showResponse,
        url: "ajax/controller.php",
        resetForm: 0,
        clearForm: 0,
        data: {
            processTicket: 1
        }
    };
    $("#admin_form").ajaxForm(options);
});

function showResponse(msg) {
    hideLoader();
    $(this).html(msg);
    $("html, body").animate({
        scrollTop: 0
    }, 600);
}

0 个答案:

没有答案