..is not a function錯誤的可能狀況:java
一、JS引入的路徑不對。檢查方法是看瀏覽器控制檯是否將JS載入了進來。ajax
二、JS引入順序不對。JS要在你使用以前引入json
三、Jquery沒有第一個引入。瀏覽器
四、函數所在script標籤,存在錯誤函數。服務器
五、函數名寫錯了。app
而後我發現按照網上不少人的寫法,不管如何都會出這個錯。 這種寫法相似:jsp
function ajaxFileUpload(){ $.ajaxFileUpload( { url:'update.do?method=uploader', //須要連接到服務器地址 secureuri:false, fileElementId:'houseMaps', //文件選擇框的id屬性 dataType: 'xml', //服務器返回的格式,能夠是json success: 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 progress var $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 file return 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"); });