我在使用Uploadify後返回JSON數據時遇到問題。json返回數據在IE或Chrome中不起作用
此代碼適用於Firefox,但不適用於IE 9或Google Chrome。
這是Uploadify腳本腳本:
jQuery("#uploadify_gallery").uploadify({
'queueID' : 'fileQueue',
'uploader' : siteURL + '/wp-content/plugins/uploadify/uploadify.swf',
'script' : siteURL + '/wp-content/plugins/uploadify/uploadify_gallery.php',
'fileExt' : '*.jpg;*.jpeg;*.png',
'auto' : true,
'multi' : true,
'method' : 'POST',
'buttonImg' : siteURL + '/wp-content/themes/storelocator/img/buttons/img_upload_grey_bg.png',
'cancelImg' : siteURL + '/wp-content/plugins/uploadify/cancel.png',
'queueSizeLimit' : 20,
'scriptData' : {'entity':jQuery('#entity').val(),'entity_id':jQuery('#entity_id').val()},
'onComplete' : function(event, queueID, fileObj, response, data) {
alert('test'); // <-- THIS WORKS
//This makes the json response readable
var result = eval("(" + response + ")");
alert(result.toSource()); // <-- this never fires
},
});
這是我在uploadify_gallery.php
與測試代碼:
$res = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($res);
昨天的工作,而且我找到了工作
有關我如何完成這項工作的任何建議?
Eval是壞的。不惜一切代價避免它。另外,服務器返回到腳本的JSON看起來像什麼? – GordonM 2012-02-01 10:21:41