Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery在提交之前不起作用_Javascript_Jquery_Html_Ajaxsubmit - Fatal编程技术网

Javascript jquery在提交之前不起作用

Javascript jquery在提交之前不起作用,javascript,jquery,html,ajaxsubmit,Javascript,Jquery,Html,Ajaxsubmit,Im使用html5的能力来读取图像的宽度和高度,然后再提交。。。 好吧,这并不完全是真的,这似乎是功能所需的时间: reader.readAsDataURL(); reader.onload = function(); image.onload = function(); 读取文件的时间比我的表单在发送图片之前所能等待的时间要多得多。 我可以检查beforeSubmit功能是否已触发,但表单在完成之前已提交。 另一件奇怪的事情是,我用一个简单的返回错误语句替换了beforeSubmit函数的

Im使用html5的能力来读取图像的宽度和高度,然后再提交。。。 好吧,这并不完全是真的,这似乎是功能所需的时间:

reader.readAsDataURL(); 
reader.onload = function();
image.onload = function();
读取文件的时间比我的表单在发送图片之前所能等待的时间要多得多。 我可以检查beforeSubmit功能是否已触发,但表单在完成之前已提交。
另一件奇怪的事情是,我用一个简单的返回错误语句替换了beforeSubmit函数的内容,表单仍在提交中。
我是否遗漏了ajaxSubmit中的beforeSubmit选项

beforeSubmit函数已最小化为返回false语句,下面是submit(表单位于dialog()中,这可能是线索吗?:

$('.block .imgpop').on("click",function()
{
    type = $(this).attr('emimage');
    currentype = type;
    options = 
    {
        type: 'POST',
        target:   '#uploadverbose',
        beforeSend:  beforeSubmit,
        resetForm: true,
        success: showResponse,
        data: { type: $(this).attr('emimage'), tempname: $(this).attr('id'), maxsize: imgsizesW[$(this).attr('emimage')] },
        dataType : "text"
    };
    $('#uploadbitch').dialog(
    {
        closeOnEscape: true,
        width: 800,
        modal: true 
    });
    return false;
});

$(document).on("click","#MyUploadForm input[type=submit]", function(e, submit)
{
        if (!submit) e.preventDefault();
        $('#MyUploadForm').ajaxSubmit(options);                                 
    });

如果您尝试处理onclick on submit按钮,则不会阻止表单提交。

这可能不是正确的答案,但它可以工作。我已将所有图像测试放在带有“更改”事件的输入字段中,对我来说效果很好。表单提交中的早熟问题仍然没有解决。

如果我用“单击”代替“提交”当我点击“提交”按钮时,它不仅会立即触发,还会打开php页面。更准确地说:我犯了一个错误,没有复制您编写的所有内容,使用您的确切代码,它的工作原理与以前完全相同:beforeSubmit被触发,但它不会阻止表单提交。
$(document).on("submit","#MyUploadForm", function(e, submit)
{
         e.preventDefault();
        $('#MyUploadForm').ajaxSubmit(options);                                 
});