JQuery encapsulates common Ajax methods (recommended) and jqueryajax

Source: Internet
Author: User

JQuery encapsulates common Ajax methods (recommended) and jqueryajax

Why easy-ajax

Easy-ajax is generated to manage the frontend garbled Ajax method. Some common methods are encapsulated based on jquery, And the frontend data cache function is planned to be added later.

The usage is as follows:

<script src="easy.ajax.js"></script>

API:

Config configuration items:

In config {jqueryAjax, the following configuration is added by default: mustCallback: Forced callback (in many cases, after a request fails, an error message returned by the backend is returned directly in Ajax, which does not enter the callback function, however, it is difficult to avoid failure and the logic needs to be processed. Therefore, with this configuration added, the callback in the configuration is executed no matter the failure is successful, provided that a function is returned .)}

Use the from form method to process the parameter request background (used when the interface uses @ RequestParam)

EasyAjax.post_form_json

Common Request (used when @ RequestBody is used for the interface)

EasyAjax.post_json

File Upload Method 1:

Var file = $ (". xxx "). get (0 ). files [0]; var fileData = new FormData (); fileData. append ("file", file); EasyAjax. ajax_Upload_File ({url: "URL", data: fileData}, function (data) {if (data. success) {// upload successful }});

File Upload Method 2:

You can directly configure the elem method as follows:

EasyAjax. ajax_Upload_File_Elem ({url: "URL", elem: "# icon"}, function (res) {if (res. success) {// uploaded successfully }});

The above is the JQuery encapsulated Ajax common method (recommended) introduced by xiaobian. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in time!

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.