Ajaxfileupload File Upload

Source: Internet
Author: User
Tags jquery library

From: http://blog.sina.com.cn/s/blog_677b66170100lnek.html

You need to use the jquery library file and the ajaxfileupload Library File

Use instance

Http://www.phpletter.com/contents/ajaxfileupload/ajaxfileupload.js

1. Contains the file section

  1. <SCRIPT type = "text/JavaScript" src = "jquery. js"> </SCRIPT>
  2. <SCRIPT type = "text/JavaScript" src = "ajaxfileupload. js"> </SCRIPT>

Ii. html Section

  1. Loading"Src =" loading.gif "style =" display: none; ">
  2. <Input id ="Filetoupload"Type =" file "size =" 20 "name ="Filetoupload"Class =" input ">
  3. <Button class = "button" id = "buttonupload" onclick = "ReturnAjaxfileupload(); "> Upload </button>

You only need three elements, one dynamic loading small icon, one file domain, and one button.
Note: you do not need to use the ajaxfileupload plug-in to upload a file:

  1. <Form name = "form" Action = "" method = "Post" enctype = "multipart/form-Data">
  2. ...... Related HTML code ......
  3. </Form>

Because the ajaxfileupload plug-in automatically generates a form submission form.

For the file domain ID and name, The fileelementid parameter of the ajaxfileupload plug-in needs to obtain the file domain ID. If you want to process the file upload operation, you need to know the file domain name to obtain the information of the file to be uploaded, the relationship between the two must be clear.

Iii. Javascript

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> 

Description of main parameters:
1. the URL indicates the file path for processing the file upload operation. You can test whether the URL can be accessed directly in the browser. For example, upload. php
2. fileelementid indicates the file domain ID, as shown above: filetoupload
3. Whether secureuri enables secure submission. The default value is false.
4. datatype data. Generally, the original structure of JSON and JavaScript is selected.
5. success: the post-processing function is successfully submitted.
6. Error submission failure Handler

There are two methods above. A small dynamic loading icon prompts the loading () function and the ajaxfileupload file to upload $. ajaxfileupload () function, which corresponds to jquery. ajax () functions are similar and easy to use. Here I omit PHP to process uploaded files. Using the jquery plug-in ajaxfileupload to implement Ajax files is that simple.

At the same time, we need to know the relevant error messages

1. syntaxerror: missing; before statement Error
If this error occurs, check whether the URL path can be accessed.

2. syntaxerror: syntax error
If this error occurs, check whether the PHP file for processing the submitted operation has a syntax error.

3, syntaxerror: Invalid property ID Error
If this error occurs, check whether the property ID exists.

4, syntaxerror: missing} in XML expression Error
If this error occurs, check whether the file domain name is consistent or does not exist.

5. other custom errors
You can directly print the variable $ error to check whether the parameters are correct, which is much more convenient than the above error prompts.

 

Upload. php

 $ Error = 'error description define ';

 $ MSG = 'value to be returned ';

Echo "{";
Echo  "Error: '". $ error. "', \ n ";
Echo  "MSG: '". $ msg. "' \ n ";
Echo "}";

Note that you want to return the value $ MSG,$ Error value must be blank

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.