开发者

coldfusion ajax jquery file-upload not working

Here's my situation. I have a photo administration page which includes 1) a photo upload template 2) a photo details template 3) a featured photo template 4) a photo gallery and 5) a dynamic nav bar. Originally, the photo upload template was set up as a form which submitted to itself and which used cffile to upload the new photo. This worked well until I tried to add jquery callbacks to refresh the details, featured photo, and gallery containers on successful upload - but I find that after the form is submitted and the photo is uploaded, any other functions that I attach to the form's submit button don't run.

Because of that, I decided to change the submit button to be type "button" and use jquery .ajax() to upload the file, so I could add my callbacks on success. My code for the ajax method so far is:

$.ajax({
            url: 'Administration/PhotoManagement/uploadPhotos.cfm',
            type: 'POST',           
            data: { Add: 'add',
                NewFilename: file_name,
                shortName: short_name,
                description: description
            },
            contentType: 'multipart/form-data',
            success: function(response, status, xhr){
                    $('#upload').html(response);
                    // refresh gallery, featured pic, details
                    alert('success');
                }
            },
            error: function(xhr, status){
                alert(status + ' ' + xhr.statusText);
            }           
开发者_开发知识库        });

On submit, I get 500 internal server error. Firebug console reports that the data got posted correctly, but the image doesn't get uploaded and I don't get an error message from the try/catch error code that I have around the cffile.

I'm not married to either approach - I'd be fine with going back to the original approach if I could get the callbacks to work. Any suggestions? If you think I should stay with the ajax approach, what would you recommend I try to fix my errors?

Edit: in the code above, I had added type:multipart/form data because I had been getting an error from my try/catch block around the tag:

Invalid content type: application/x-www-form-urlencoded; charset=UTF-8


I'm a little late to the party, but I've used this before as an AJAX fileuploader using coldfusion:

http://valums.com/ajax-upload/

When you download the package there is an example using coldfusion.

In the javascript file, there is a function that has a callback method called 'onComplete' (Search for qq.FileUploaderBasic). In that callback method call your own callback function like this:

onComplete: function(id, fileName, responseJSON)
    {
        uploaderCallBackFunction(id, fileName, responseJSON);
    },

Where uploaderCallBackFunction is a function I wrote. You can pass JSON from the CFC to the callback function if you would like too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜