Home>Article>Backend Development> Detailed explanation of steps to implement php+ajax file upload without refresh

Detailed explanation of steps to implement php+ajax file upload without refresh

php中世界最好的语言
php中世界最好的语言 Original
2018-05-18 14:54:16 1775browse

This time I will bring you php ajax without refreshFile uploaddetailed implementation steps, php ajax without refresh file uploadWhat are the precautions, the following is a practical case, one Get up and take a look.

Form format for file upload

AjaxFileUpload achieves better asynchronous file upload effect and is easy to use:

       

Upload can also pass parameters:

var data = { name: 'my name', description: 'short description' } $.ajaxFileUpload({ url: 'upload.php', secureuri: false, data: data, fileElementId: 'fileToUpload', dataType: 'json', success: function (data) { alert(data.msg); }, error: function (data) { alert("error"); } });

Main parameter description:

1. url represents the file path ofprocessing fileupload operation. You can test whether the URL can be directly accessed in the browser, as above: upload. php
2. fileElementId represents the file domain ID, as above: fileToUpload
3. Whether secureuri enables secure submission, the default is false
4. dataType data, generally choose json, the original ecology of javascript
5 、Processing function after successful submission
6、Error processing function for failed submission

Need to understand the relevant error prompts

1. SyntaxError: missing; before statement error

If this error occurs, you need to check whether the url path is accessible

2, SyntaxError: syntax error

If this error occurs, you need to check the PHP file that handles the submission operation Whether there is asyntax error

3. SyntaxError: invalid property id error

If this error occurs, you need to check whether thepropertyID exists

4. SyntaxError: missing } in XML expression error

If this error occurs, you need to check whether the file domain name is consistent or does not exist

5.Other custom errors

You can use the variable $error to print directly to check whether each parameter is correct, which is much more convenient than the invalid error prompts above.

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

Recommended reading:

PHP long connection use case analysis

QQ, WeChat and Alipay three-in-one payment code How to implement

with PHP

The above is the detailed content of Detailed explanation of steps to implement php+ajax file upload without refresh. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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