0

Im using html5 capacities to read image width and height before submitting... Well, this is not happening exactly, it seems like the time needed for the functions:

reader.readAsDataURL(); 
reader.onload = function();
image.onload = function();

To read the file is way too much than the time my form is able to wait before sending the pic. I can check that the beforeSubmit function is triggered, but the form is submitted before it finishes.
Another weird thing is that I have replaced the beforeSubmit function content with a simple return false sentence and the form is being submitted anyway.
Am I missing something regarding the beforeSubmit option in ajaxSubmit?

The beforeSubmit function has been minimized to a return false statement, here comes the submit (the form is inside a dialog(), may be this the clue?:

$('.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);                                 
    });
user997593
  • 423
  • 5
  • 16

2 Answers2

0
$(document).on("submit","#MyUploadForm", function(e, submit)
{
         e.preventDefault();
        $('#MyUploadForm').ajaxSubmit(options);                                 
});

If you try to handle onclick on submit button then it doesn't stop form from submitting.

Amit Garg
  • 3,867
  • 1
  • 27
  • 37
  • If I substitute the "click" for the "submit" when I click on the submit button it not only fires immediately, but it also opens the php page. – user997593 Mar 04 '14 at 17:55
  • To be more accurate: I made a mistake and I didn't copied everything you wrote, with your exact code, it works exactly as before: the beforeSubmit is triggered but it doesn't prevent the form to be submitted. – user997593 Mar 04 '14 at 17:59
0

It may bot be exactly the answer, but it works. I have place all the image testing in the input field with a "change" event and it works just fine for me. Precocity in the form submitting is still unsolved.

user997593
  • 423
  • 5
  • 16