JSON POST WITH PHP IN ANGULARJS - Wikitechy

| AngularJS Step By Step Tutorials

JSON POST WITH PHP IN ANGULARJS

The POST method is used to insert the data. In AngularJS, we should post the form data in JSON format to insert into the

PHP file. The PHP server side code used to get the posted data from AngularJS and

decode to JSON format.

Sample code for JSON post with PHP in AngularJS:

Wikitechy AngularJS Tutorials

JSON POST with PHP in AngularJS Enter Name : Enter Mobile : Enter Email : Insert {{content}} Please Use Ctrl+F5 for Refresh.

wikitechy

WikitechyCom ? Copyright 2016. All Rights Reserved.

| AngularJS Step By Step Tutorials

var app = angular.module("myApp", []); app.controller("jsonPostCtrl", function($scope, $http) {

$scope.user = {}; $scope.submitForm = function() {

$http({ method : 'POST', url : 'insert.php', data : $scope.user, headers : {'Content-Type': 'application/x-www-form- urlencoded'}

}) .success(function(data) { $scope.content = data; }); }; });

POST Data to PHP File in JSON format:

Set of data has been posted through AngularJS to PHP and retrieve the result

from PHP file.

$scope.submitForm = function() { $http({ method : 'POST', url : 'insert.php', data : $scope.user, headers : {'Content-Type': 'application/x-www-form-urlencoded'} }) .success(function(data) { $scope.content = data;

});

wikitechy

WikitechyCom ? Copyright 2016. All Rights Reserved.

| AngularJS Step By Step Tutorials

Code Explanation for JSON post with PHP in AngularJS:

1. The name="userForm" is used to give the form name as userForm. 2. The submitForm() function is used to call the function on form submit. 3. The textbox is used to get the name from the user. 4. The textbox is used to get the Mobile Number from the user. 5. The textbox is used to get the email from the user.

wikitechy

WikitechyCom ? Copyright 2016. All Rights Reserved.

| AngularJS Step By Step Tutorials

6. The {{content}} is used to display the $msg when the user click the submit

button.

7. The "jsonPostCtrl" is used to create the controller for the Application with

arguments $scope object and $http service.

8. The submitForm function is used to POST the submitted data $scope.user

to the "insert.php".

9. The $scope.content=data is used to get the updated results as response

data.

Sample code for insert.php:

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download