我正在尝试通过以下简单代码将图像上传到服务器:
<form enctype="multipart/form-data">
<input name="file" type="file" />
<input type="button" value="Upload" />
</form>
<progress></progress>
<script>
$(':button').click(function(){
var formData = new FormData($('form')[0]);
$.ajax({
url: 'http://cs418417.vkontakte.ru//upload.php?act=do_add&mid=219171498&aid=179524586&gid=0&hash=154ebcc2f733f318a20b77e296f285c5&rhash=e7df1f0c685b918ffa58ff10937dc7cd&swfupload=1&api=1', //Server script to process data
type: 'POST',
dataType: "jsonp",
xhr: function() {
var myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){
myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // For handling the progress of the upload
}
return myXhr;
},
data: formData,
cache: false,
contentType: false,
processData: false
});
});
function progressHandlingFunction(e){
if(e.lengthComputable){
$('progress').attr({value:e.loaded,max:e.total});
}
}
</script>
此代码不起作用。控制台向我显示这样的错误:
问题出在哪里?提前感谢,对不起我的英语!