Thinkphp combined with ajaxFileUpload for asynchronous image transmission Sample code

Source: Internet
Author: User
This article mainly introduces how to use Thinkphp and ajaxFileUpload to implement asynchronous image transmission. This article provides detailed sample code, which is of reference value to everyone, let's take a look. This article mainly introduces how to use Thinkphp and ajaxFileUpload to implement asynchronous image transmission. This article provides detailed sample code, which is of reference value to everyone, let's take a look.

Preface

Before doing this project, the process of uploading images has always been directly using form submission for file transmission. this time, due to requirements, asynchronous transmission of images is required, although implementation is not difficult, after all, there are too many plug-ins, but it still wastes a long time for debugging. The reason is that I used the plug-in ajaxfileupload in ancient times and reported frequent errors when I first started using it, handler is not a function.

With a heavy mood, I tried Baidu and found the answer. I couldn't help but feel that the search engine is really powerful.

Solution

The reason for the above error is that jquery no longer uses the handler method from 1.9.0. the specific reason is unknown, so it can only be downloaded jQuery.extend({Add code manually:


handleError: function( s, xhr, status, e ){// If a local callback was specified, fire itif ( s.error ) {s.error.call( s.context || s, xhr, status, e );}// Fire the global callbackif ( s.global ) {(s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );}}

, Continue debug


$. Ajaxfileupload ({url: '', secureuri:'', fileElementId: '', --> enter the input file ID data: {}, dataType: 'json ', complete: function (data ){}})

The code does not report an error, but there are new problems. the returned data is always undefined. then I checked the debugging tool and returned the value. The format is correct, after thinking about it, go again .................. baidu,

Then we made two adjustments:

1. seteval('data = '+ data) ; Replacedata = jQuery.parseJSON(jQuery(data).text());

2. replace the complete method with success

OK. the data returned by the backend can be printed.

Summary

The above is a detailed description of the sample code for asynchronous image transmission using Thinkphp and ajaxFileUpload. For more information, see other related articles in the first PHP community!

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.