javascript - AngularJS and PHP - Notice: Undefined property: stdClass -


i have simple patch http request angularjs php , i'm getting error notice: undefined property: stdclass::$todoname in console. here codes:

html

<div ng-controller="updatetodocontroller"> <div class="input-field col s12" ng-repeat="t in todo">       <input id="{{ t.id }}" type="text" class="validate" ng-model="todoname">       <label class="active" for="{{ t.id }}">{{ t.name }}</label>       <button class="btn waves-effect waves-light" ng-click="updatetodo(t.id)">update       </button> </div> </div> 

controller

function updatetodocontroller($http, $scope, $routeparams, $location) {       $scope.updatetodo = function(todoid) {          var req = {          method: 'patch',          url: 'app/endpoints/update-todo.php',          headers: {            'content-type': 'application/x-www-form-urlencoded'          },          data: {              todoname: $scope.todoname,             todoid: todoid             }         }          $http(req)         .then(function successcallback(response) {             $location.url('/');             console.log(response);         }, function errorcallback(response) {             console.log(response);         });     }  } 

update-todo.php

$data = json_decode(file_get_contents('php://input'));  $todoid = $data->todoid; $todoname = $data->todoname;  $statement = $db->prepare("update todo_list set name=? id=?"); $statement->execute(array($todoname, $todoid)); $results=$statement->fetchall(pdo::fetch_assoc); echo json_encode($results); 

it updates specific field id gives null value. missing here? thank you.

you sending data form-urlencoded trying use json_decode on it.

remove content-type header angular request.

$http default send application/json.

a simple test return dump of $data , inspect in browser dev tools


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -