私はjQueryのアップロードプラグインを使用することをお勧めします。 http://valums.com/ajax-upload/return jsonオブジェクトのデコードにjqueryを使用するにはどうすればよいですか?
返信応答の種類をjsonに設定すると、返すjsonオブジェクトの処理方法を尋ねるダイアログがfirefoxによってポップアップされます。
アップロードスクリプトの作成者のページで同じ質問が表示されていますが、これまで回答がありませんでした。うまくいけば、ここの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をデコードするための別のプラグインを必要としません。 –