我想爲jQuery使用上傳插件。 http://valums.com/ajax-upload/如何使用jquery解碼返回的json對象?
當我設置返回響應類型JSON,Firefox會彈出一個對話框,詢問我怎麼樣來處理返回的JSON對象。
人們在上傳腳本的作者頁面上提出了同樣的問題,但目前爲止還沒有答案。希望在這裏的JavaScript人可以找出我們如何處理這個問題。
謝謝。
<script type= "text/javascript">
/*<![CDATA[*/
$(document).ready(function(){
/* example 1 */
var button = $('#button1'), interval;
new AjaxUpload(button, {
//action: 'upload-test.php', // I disabled uploads in this example for security reasons
action: '/posts/upload_images/',
name: 'myfile',
responseType: 'json',
onSubmit : function(file, ext){
// change button text, when user selects file
button.text('Uploading');
// If you want to allow uploading only 1 file at time,
// you can disable upload button
this.disable();
// Uploding -> Uploading. -> Uploading...
interval = window.setInterval(function(){
var text = button.text();
if (text.length < 13){
button.text(text + '.');
} else {
button.text('Uploading');
}
}, 200);
},
onComplete: function(file, response){
var json = response;
alert(json);
button.text('Upload');
window.clearInterval(interval);
// enable upload button
this.enable();
// add file to the list
// $('<li></li>').appendTo('#example1 .files').text(json.response_text);
$('<li></li>').appendTo('#example1 .files').text(file);
}
});
});
/*]]>*/
</script>
我不能從經驗中發言,但希望他使用該插件還不需要其他的插件解碼JSON。 – 2009-05-02 17:42:39