JQuery ajaxSubmit 函数不适用于 AngularJS HTML 页面中的表单
JQuery ajaxSubmit function is not working for a form in an AngularJS HTML page
我正在尝试使用 AngularJS 修补遗留图片上传代码。
我有一个包含表单的 HTML 页面。以下是代码的 HTML 部分。
<form name="testForm" ng-init="testfunc()" novalidate>
<div id="adduser_header">
<div>
<p><b>Add new user</b></p>
</div>
</div>
<div id="userInfo">
<div>
<label>First Name</label>
<input type="text" name="fname" required>
</div>
<div>
<label>Last Name</label>
<input type="text" name="lname" required>
</div>
<div>
<form id="imageuploadForm"
action="/Projectname/jersey/ImageUploader/uploadimage"
method="POST" enctype="multipart/form-data"
accept-charset="utf-8" name="submitForm">
<div>
<input id="imagename" type="text" readonly="readonly"
placeholder="Click browse to upload image">
<div id="uploadImgBtn" onclick="getImgFile()">
<span>Browse</span>
</div>
</div>
<input id="userID" name="userID" type="hidden">
<input id="userImage" name="userImage" type="hidden">
<input id="usertType" name="usertType" type="hidden">
<p style="display: none;">this is your file input tag, so i hide it!
i used the onchange event to fire the form submission</p>
<div><input id="uploadimgfile" type="file" value="upload"
required="required" autofocus="autofocus"
name="imgfile"
onchange="upImgFile(this, event)">
</div>
<input style="display: none;" type="submit" value="Send">
</form>
</div>
</div>
<div id="action_buttons">
<input id="save_user" value="Add User" type="button"
title="Add User"
ng-click="submitRegistrationForm()"
ng-disabled="testForm.$invalid">
<a ui-sref="home-admin" ng-click="return()">
<input id="canceltoreturn" value="Cancel" type="button" title="Cancel">
</a>
</div>
</form>
我可以毫无问题地浏览和 select 图片。当我尝试提交此 AngularJS 表单时,我的问题就开始了。当我单击 添加用户 时,我首先提交 AngularJS 名为 testForm 的表单,其中 returns 成功,ID 为用户。此 ID 传递给以下代码补丁 (legacy):
uploadImage: function(id)
{
if($('#imageuploadForm').find('#userImage').val() != "")
{
$("#imageuploadForm").find("#userID").val(id);
var uploadstatus = null;
$("#imageuploadForm").ajaxSubmit({
success: function(data)
{
uploadstatus = data;
if(uploadstatus == "uploaded")
{
console.log("Uploaded Successfully!");
}
if(uploadstatus == "updated")
{
console.log("Updated Successfully!");
}
else
if(uploadstatus == "problem" || uploadstatus == "notuploaded")
{
console.log("Some problem occurred!");
}
$("#imagename").val("");
$('#imageuploadForm').find('#userImage').val("");
},
error: function(xhr, ajaxOptions, thrownError)
{
console.log(xhr.status);
}
});
}
else
{
alert("Please select some image to upload!")
}
}
当我调试代码时,它一直到行。
$("#imageuploadForm").ajaxSubmit
但没有进一步发生。 action属性中提到的服务(/Projectname/jersey/ImageUploader/uploadimage)根本没有被调用
当表单完全在 HTML 中时,此 ajaxSubmit 运行良好。 (此外,我正在为 ajaxSubmit 函数使用 jquery.form.js。)
但是由于我以 AngularJS 的方式定制了代码,图像上传已停止工作。
我在这里做错了什么?我无法理解。我该如何解决这个问题?
嵌套 <form>
个元素是非法的。
来自文档:
The HTML <form>
element represents a document section containing interactive controls for submitting information.
Content categories: Flow content, palpable content
Permitted content: Flow content, but not containing <form>
elements
Tag omission: None, both the starting and ending tag are mandatory.
Permitted parents: Any element that accepts flow content
有关详细信息,请参阅
我正在尝试使用 AngularJS 修补遗留图片上传代码。 我有一个包含表单的 HTML 页面。以下是代码的 HTML 部分。
<form name="testForm" ng-init="testfunc()" novalidate>
<div id="adduser_header">
<div>
<p><b>Add new user</b></p>
</div>
</div>
<div id="userInfo">
<div>
<label>First Name</label>
<input type="text" name="fname" required>
</div>
<div>
<label>Last Name</label>
<input type="text" name="lname" required>
</div>
<div>
<form id="imageuploadForm"
action="/Projectname/jersey/ImageUploader/uploadimage"
method="POST" enctype="multipart/form-data"
accept-charset="utf-8" name="submitForm">
<div>
<input id="imagename" type="text" readonly="readonly"
placeholder="Click browse to upload image">
<div id="uploadImgBtn" onclick="getImgFile()">
<span>Browse</span>
</div>
</div>
<input id="userID" name="userID" type="hidden">
<input id="userImage" name="userImage" type="hidden">
<input id="usertType" name="usertType" type="hidden">
<p style="display: none;">this is your file input tag, so i hide it!
i used the onchange event to fire the form submission</p>
<div><input id="uploadimgfile" type="file" value="upload"
required="required" autofocus="autofocus"
name="imgfile"
onchange="upImgFile(this, event)">
</div>
<input style="display: none;" type="submit" value="Send">
</form>
</div>
</div>
<div id="action_buttons">
<input id="save_user" value="Add User" type="button"
title="Add User"
ng-click="submitRegistrationForm()"
ng-disabled="testForm.$invalid">
<a ui-sref="home-admin" ng-click="return()">
<input id="canceltoreturn" value="Cancel" type="button" title="Cancel">
</a>
</div>
</form>
我可以毫无问题地浏览和 select 图片。当我尝试提交此 AngularJS 表单时,我的问题就开始了。当我单击 添加用户 时,我首先提交 AngularJS 名为 testForm 的表单,其中 returns 成功,ID 为用户。此 ID 传递给以下代码补丁 (legacy):
uploadImage: function(id)
{
if($('#imageuploadForm').find('#userImage').val() != "")
{
$("#imageuploadForm").find("#userID").val(id);
var uploadstatus = null;
$("#imageuploadForm").ajaxSubmit({
success: function(data)
{
uploadstatus = data;
if(uploadstatus == "uploaded")
{
console.log("Uploaded Successfully!");
}
if(uploadstatus == "updated")
{
console.log("Updated Successfully!");
}
else
if(uploadstatus == "problem" || uploadstatus == "notuploaded")
{
console.log("Some problem occurred!");
}
$("#imagename").val("");
$('#imageuploadForm').find('#userImage').val("");
},
error: function(xhr, ajaxOptions, thrownError)
{
console.log(xhr.status);
}
});
}
else
{
alert("Please select some image to upload!")
}
}
当我调试代码时,它一直到行。
$("#imageuploadForm").ajaxSubmit
但没有进一步发生。 action属性中提到的服务(/Projectname/jersey/ImageUploader/uploadimage)根本没有被调用
当表单完全在 HTML 中时,此 ajaxSubmit 运行良好。 (此外,我正在为 ajaxSubmit 函数使用 jquery.form.js。) 但是由于我以 AngularJS 的方式定制了代码,图像上传已停止工作。 我在这里做错了什么?我无法理解。我该如何解决这个问题?
嵌套 <form>
个元素是非法的。
来自文档:
The HTML
<form>
element represents a document section containing interactive controls for submitting information.Content categories: Flow content, palpable content
Permitted content: Flow content, but not containing
<form>
elementsTag omission: None, both the starting and ending tag are mandatory.
Permitted parents: Any element that accepts flow content
有关详细信息,请参阅