$.AjaxFileUpload is not a function

..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',                                     //服务器返回的格式,可以是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");
		});

转载于:https://my.oschina.net/u/2437172/blog/653254

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值