gpt4 book ai didi

javascript - Angular 表单未提交

转载 作者:行者123 更新时间:2023-12-03 09:22:54 26 4
gpt4 key购买 nike

我有这个 Angular 脚本

var app = angular.module('j_app', ['ngMaterial'], function($interpolateProvider)    {
$interpolateProvider.startSymbol('<%');
$interpolateProvider.endSymbol('%>');
});

app.controller('j_controller', function($scope, $http) {
$scope.formdata = {};

$scope.formsubmit = function(){
$http({
method : 'POST',
url : '/dodong',
data : $.param($scope.formdata),
headers : {'Content-Type' : 'application/x-www-form-urlencoded'}
}).success(function(data){
console.log(data);
});
};
});

还有这个 Angular 形

<body ng-app="j_app">
<div ng-controller="j_controller">
<form ng-submit="formsubmit()">
<fieldset>
<input type="text" name="username" ng-model="formdata.username" placeholder="Your username here..." />
<input type="password" name="password" ng-model="formdata.password" placeholder="Your password here..." />
</fieldset>
<button>Submit test angular</button>
</form>
</div>
</body>

但是表单没有提交,就像什么也没发生一样,但也没有抛出错误。有什么想法吗?

最佳答案

如果您在 Plunker 中输入以下内容,它将起作用:

<!doctype html>
<html lang="en">

<head>
<meta charset="UTF-8">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
</head>

<body ng-app="submitTest">
<script>
angular.module('submitTest', [])
.controller('j_controller', ['$scope', function($scope) {
$scope.text = 'type something, will ya';
$scope.formsubmit = function() {
alert("Called");
};
}]);
</script>
<div ng-controller="j_controller">
<form ng-submit="formsubmit()">
<fieldset>
<input type="text" ng-model="text" name="text" />
</fieldset>
<input type="submit" id="submit" value="Submit" /> </form>
</div>
</body>

</html>

您需要使用<input type="submit"> .

关于javascript - Angular 表单未提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31789767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com