File upload form submission

I am having problems downloading a file when using jquery.

I have the following HTML in the form.

<fieldset>
  <ul>
    <li> 
      <div class="field"><input size="35" type="file"
                             name="formFile" id="formFile"/></div> 
    </li>
    <li> 
      <div class="field"><input size="35" type="text" 
                             name="formFileName" id="formFileName" /></div>
    </li>
  </ul> 
</fieldset>

To publish the data, I use $('#myForm').ajaxForm(

When I send data and the received data contains some javascript, javascript is not recognized.

I expected javscriptcode to start when the data is received, but this will happen early. The results show that $ or jquery could not be found.

If I remove the name attribute from the input type = file element, there are no errors, but this is not the right solution.

How could this happen?

+3
source share
1 answer

, JS .

$('#myForm').ajaxForm(function() { 
  //Do your JS execution
}); 

$.get(), $.post(). $ajaxForm() .., $.ajax().

ajaxSubmit(), $.ajax, , , : false /.

// attach handler to form submit event 
$('#myFormId').submit(function() { 
    // submit the form 
    $(this).ajaxSubmit({
                       success: function(result){ callbackFunction(result); }
                       ,error: function(msg,XMLStatus,err){ errFunction(msg,XMLStatus,err); }
                       }); 
    // return false to prevent normal browser submit and page navigation 
    return false; 
});

, .

+1

Source: https://habr.com/ru/post/1747312/


All Articles