jQuery Uploadify-如何使用onComplete?
我正在使用uploadify: 并有一个完整的:jQuery Uploadify-如何使用onComplete?,jquery,uploadify,Jquery,Uploadify,我正在使用uploadify: 并有一个完整的: onComplete: function(response) { alert(response); }, 我的服务器正在发送回相册\u id。。。我如何在响应中访问它 谢谢 更新 onComplete: function(response) { jsonObject = jQuery.parseJSON(response.response); alert (jsonObject);
onComplete: function(response) {
alert(response);
},
我的服务器正在发送回相册\u id。。。我如何在响应中访问它
谢谢
更新
onComplete: function(response) {
jsonObject = jQuery.parseJSON(response.response);
alert (jsonObject);
alert(jsonObject.album_id);
},
两个警报都不运行
更新2
发送回JSON的RAils代码?也许这就是问题所在
render:json=>{:result=>'success',:album_id=>3113}我相信返回的响应是:
function UploadComplete(event, queueID, fileObj, response, data) { }
很明显,无论你返回什么,都会得到回应。在我的例子中,它是一个FlickpPhotoId,因为我的uploadify脚本正在将文件上载到Flickr,然后等待ID
如果您的响应是一个json对象,那么您需要解析它。onComplete将发送四个参数。所以你的函数应该是这样的:
onComplete: function(event, queueID, fileObj, response, data) {
alert(response.responseText);
return false;
},
返回false是为了避免触发默认函数。以上答案正确地指向了onComplete方法。我要补充的唯一一件事是,请你发布你的整个上传电话。onComplete需要在您的调用中构建。应该是这样的
$('#sampleFile').uploadify({
'uploader': 'include/uploadify/uploadify.swf',
'script': 'add_list.php',
'scriptData': {'mode': 'upload'},
'fileDataName': 'newUpload',
'folder': '/work/temp/uploads',
'cancelImg': 'images/cancel.png',
'queueID': 'uploadQueue',
'onComplete': function (event, queueID, fileObj, response, data) {
// A function that triggers when a file upload has completed. The default
// function removes the file queue item from the upload queue. The
// default function will not trigger if the value of your custom
// function returns false.
// Parameters
// event: The event object.
// queueID: The unique identifier of the file that was completed.
// fileObj: An object containing details about the file that was selected.
// response: The data sent back from the server.
// data: Details about the file queue.
}
});
//您必须首先将其作为一个整体对象进行解析 jsonObject=jQuery.parseJSON(响应) //然后在之后访问对象属性或方法
警报(jsonObject.album_id) 现在的响应是[object],也许rails没有返回正确的响应?我把它硬编码了。Uploadify想要JSON,对吗?render:json=>{:result=>'success',:album_id=>3113}对不起!您应该使用
alert(response.responseText)
如果返回JSON数据,则必须解析。但是,如果您只是将唱片集id作为值返回,那么这段代码可以工作