Home > Web Front-end > JS Tutorial > body text

How to submit file using AjaxSubmit()

php中世界最好的语言
Release: 2018-04-02 14:08:56
Original
2286 people have browsed it

This time I will show you how to use AjaxSubmit() to submit file files, what are the precautions for using AjaxSubmit() to submit file files, the following is a practical case, let’s take a look take a look.

I checked various methods on the Internet before. If I want to submit a file, I also need to be able to receive the return value. It is recommended to use the ajaxSubmit() method.

Most of the recommendations on the Internet are like this:

$("#formId").submit(
  $(this).ajaxSubmit({
    url:...,
    type:...,
    success:function(){
    ...
    }
  });
  return false;//阻止自动提交
);
Copy after login

But when you use it, you will find that there will be multiple submissions, one request for the first time, two requests for the second time...
And ajaxSubmit() itself has the submit() function, so there is no need to do this, just use:

var opt = {
  type:'post',            
  datatype:'json',
  url:'../../../rybmanagement/upLoadFile',            
  success: function(data) {
  ...
  }
};
$("#formId").ajaxSubmit(opt);//相当于from.submit()
Copy after login

Introduce the file:

<script src="jquery-form.js" type="text/javascript"></script>
<script src="../../js/jquery-2.1.1.min.js"></script>
Copy after login

I believe you have mastered it after reading the case in this article Method, for more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Use Blod to make ajax progress bar download

##Ajax+json to implement shopping cart settlement

The above is the detailed content of How to submit file using AjaxSubmit(). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template