我在Angular中提交带有update()函数的表单,然后进行身份验证,返回一个promise,然后在成功时提交第二个表单。
问题是,第二种形式不会使用document.getElementById(elementID).submit();方法。但是,它将使用document.getElementById(elementID).click();但当然只能在非触控设备上使用。
底线 - 为什么不能提交()工作?
这是一个简化版本的jsFiddle:http://jsfiddle.net/jimcamut/xos805gk/
这是我的函数,它以完整版本处理表单提交。
$scope.update = function(user) {
if ($scope.earlyUser.$valid) {
$scope.master = angular.copy(user);
console.log("Form submitted on front end");
// This integrates ParseJS and submits the data to a database - all good here, except after the promise
var parseUser = new Parse.Object("LaunchUser");
parseUser.setACL(new Parse.ACL());
parseUser.save({
name: $scope.master.name,
email: $scope.master.email,
zipcode: $scope.master.zipcode
},{
error: function(model, error) {
console.log("error is...");
console.log(error);
}
// Returns a promise
}).then(function(object) {
// Problem area here when attempting to submit second form...
document.getElementById('mc-embedded-subscribe').submit();
$scope.reset();
});
} else {
alert("Please correct the red form fields.");
}
};
答案 0 :(得分:0)
元素是输入,但您需要“提交()”表单。 这一行
document.getElementById('mc-embedded-subscribe').submit();
应该改为
document.getElementById('mc-embedded-subscribe-form').submit();
在这里你有一个新的小提琴这个变化,它的工作原理! http://jsfiddle.net/kx8dn8wc/