我想在表单提交事件上准备数据并将其发送到服务器。
我在step1.php文件中有一个表单
<form name="DTOstep1" >
<input type="text" name="save_quote_email" id="save_quote_email" />
<br><br>
<input type="submit" value="Save" />
</form>
当我提交此表单时,我想从 app/ctrl/autoQuoteCtrl.js 调用 Controller 函数
请告诉我如何在此处进行 api 调用以将数据(O)发送到服务器?
最佳答案
html
<form role="form" name="form1">
<div class="form-group">
<p>Welcome : <span>{{user.mail}}</span></p>
<label for="exampleInputEmail1">Mail</label>
<input type="text" placeholder="Enter name" class="form-control" ng-model="user.mail" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" placeholder="Password" id="exampleInputPassword1" class="form-control" ng-model="user.pass" required>
</div>
<button class="btn btn-default" type="submit" ng-click="login(user)" ng-disabled="form1.$invalid">Submit</button>
<p>{{msgtxt}}</p>
</form>
Controller.js
'使用严格';
app.controller('loginCtrl', ['$scope','loginService', function ($scope,loginService) {
$scope.msgtxt='';
$scope.login=function(data){
alert(JSON.stringify(user));
};
}]);
关于javascript - Angular js表单提交并将准备好的json数据发送到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38028201/