$.AjaxFileUpload is not a function
生活随笔
收集整理的這篇文章主要介紹了
$.AjaxFileUpload is not a function
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
..is not a function錯(cuò)誤的可能情況:
1、JS引入的路徑不對(duì)。檢查方法是看瀏覽器控制臺(tái)是否將JS載入了進(jìn)來(lái)。
2、JS引入順序不對(duì)。JS要在你使用之前引入
3、Jquery沒(méi)有第一個(gè)引入。
4、函數(shù)所在script標(biāo)簽,存在錯(cuò)誤函數(shù)。
5、函數(shù)名寫錯(cuò)了。
然后我發(fā)現(xiàn)按照網(wǎng)上很多人的寫法,無(wú)論如何都會(huì)出這個(gè)錯(cuò)。 這種寫法類似:
function ajaxFileUpload(){$.ajaxFileUpload({url:'update.do?method=uploader', //需要鏈接到服務(wù)器地址secureuri:false,fileElementId:'houseMaps', //文件選擇框的id屬性dataType: 'xml', //服務(wù)器返回的格式,可以是jsonsuccess: function (data, status) //相當(dāng)于java中try語(yǔ)句塊的用法{ },error: function (data, status, e) //相當(dāng)于java中catch語(yǔ)句塊的用法{}});}最后我按照官方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");});轉(zhuǎn)載于:https://my.oschina.net/u/2437172/blog/653254
總結(jié)
以上是生活随笔為你收集整理的$.AjaxFileUpload is not a function的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: [密码学基础][每个信息安全博士生应该知
- 下一篇: 浅谈-国标GB28181协议上下级对接国