$.AjaxFileUpload is not a function
生活随笔
收集整理的這篇文章主要介紹了
$.AjaxFileUpload is not a function
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
..is not a function錯誤的可能情況:
1、JS引入的路徑不對。檢查方法是看瀏覽器控制臺是否將JS載入了進來。
2、JS引入順序不對。JS要在你使用之前引入
3、Jquery沒有第一個引入。
4、函數所在script標簽,存在錯誤函數。
5、函數名寫錯了。
然后我發現按照網上很多人的寫法,無論如何都會出這個錯。 這種寫法類似:
function ajaxFileUpload(){$.ajaxFileUpload({url:'update.do?method=uploader', //需要鏈接到服務器地址secureuri:false,fileElementId:'houseMaps', //文件選擇框的id屬性dataType: 'xml', //服務器返回的格式,可以是jsonsuccess: function (data, status) //相當于java中try語句塊的用法{ },error: function (data, status, e) //相當于java中catch語句塊的用法{}});}最后我按照官方DEMO的格式寫,就OK了
<form method="post" action="" enctype="multipart/form-data"><label>File Input: <input type="file" name="file" id="demo1" /></label></form> $(document).ready(function() {var interval;function applyAjaxFileUpload(element) {$(element).AjaxFileUpload({action: "MyJsp.jsp",onChange: function(filename) {// Create a span element to notify the user of an upload in progressvar $span = $("<span />").attr("class", $(this).attr("id")).text("Uploading").insertAfter($(this));$(this).remove();interval = window.setInterval(function() {var text = $span.text();if (text.length < 13) {$span.text(text + ".");} else {$span.text("Uploading");}}, 200);},onSubmit: function(filename) {// Return false here to cancel the upload/*var $fileInput = $("<input />").attr({type: "file",name: $(this).attr("name"),id: $(this).attr("id")});$("span." + $(this).attr("id")).replaceWith($fileInput);applyAjaxFileUpload($fileInput);return false;*/// Return key-value pair to be sent along with the filereturn true;},onComplete: function(filename, response) {window.clearInterval(interval);var $span = $("span." + $(this).attr("id")).text(filename + " "),$fileInput = $("<input />").attr({type: "file",name: $(this).attr("name"),id: $(this).attr("id")});if (typeof(response.error) === "string") {$span.replaceWith($fileInput);applyAjaxFileUpload($fileInput);alert(response.error);return;}$("<a />").attr("href", "#").text("x").bind("click", function(e) {$span.replaceWith($fileInput);applyAjaxFileUpload($fileInput);}).appendTo($span);}});}applyAjaxFileUpload("#demo1");});轉載于:https://my.oschina.net/u/2437172/blog/653254
總結
以上是生活随笔為你收集整理的$.AjaxFileUpload is not a function的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [密码学基础][每个信息安全博士生应该知
- 下一篇: 浅谈-国标GB28181协议上下级对接国