我想为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