如下所示:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="angular.min.js"></script>
<script src="jquery.min.js"></script>
</head>
<body>
<div ng-app="module" ng-controller="ctrl">
<form method="post" action="ng.php">
標題: <input type="text" ng-model="field.title"><br/>
點擊數: <input type="text" ng-model="field.click"><br/>
內容: <input type="text" ng-model="field.content"><br/>
<!--將提交的數據獲取放到textarea里面-->
<textarea name="data"></textarea>
<input type="submit">
</form>
</div>
<script>
var m = angular.module('module', []);
m.controller('ctrl', ['$scope', function ($scope) {
$scope.field = {title: '泠泠', click: 100,content:'泠泠在路上'};
$('form').submit(function () {
$("[name='data']").val(angular.toJson($scope.field));
});
}]);
</script>
</body>
</html>
ng.php
<?php //print_r($_POST); $data = json_decode($_POST['data'],true); var_dump($data);
以上這篇angularJs中$scope數據序列化的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。