我一直在尝试使用AJAX实现进度条,并且我从代码中获得了ZERO输出。我想知道是否有人能让我知道我可能会失踪的东西。
$("#uploadSubmitBtn").click(function(){
var formData = new FormData($("#mediaUploadForm")[0]);
var usersFiles=$("#uploadBtn")[0].files;
formData.append('usersUpload', usersFiles);
$.ajax({
//for our progress bar...
xhr: function() {
//var xhr = new window.XMLHttpRequest();
var xhr = $.ajaxSettings.xhr();
xhr.upload.addEventListener("progress", function(evt) {
alert("attempting progress calculation..");
if (evt.lengthComputable) {
var percentComplete = Math.round( (evt.loaded * 100/ evt.total) );
console.log("percent completed = " + percentComplete);
}
}, false);
return xhr;
},//end xhr function
//other stuff
url : "upload",
type : 'post',
data : formData,
async : false,
cache: false,
processData: false,
contentType: false,
success : function(resp){
$('#msgBoxText').text(resp);
$('#msgBox').slideDown("slow");
},
});
});//end of submitting media
答案 0 :(得分:0)
所以看起来将async值设置为true可以解决问题。所以代码片段现在看起来像var formTemplate = ele.parentNode.parentNode; // your formTemplate button
var children = formTemplate.childNodes;
var textField = children.item(1); // replace "1" with the index of "textField" element in your template
var keyboard = textField.getFeature("Keyboard"); // get the textField's Keyboard element
var userValue = keyboard.text; // the value entered by the user on the Apple TV keyboard
感谢那些至少看过的人:)