javascript - How to replace ajax call with $http, AngularJs -
i trying implement angular.js in php file, because it's 1 file project, thinking use angularjs. decided replace ajax call $http
.
for imported google angular js file
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
and replace ajax call
$.ajax({ url: url, type: "get", data: data, async: false, success: function(res) { resdata = res; } });
with
$http({ url: url, method: "get", data: data }).success(function(data, status, headers, config) { resdata = data; }).error(function(data, status, headers, config) { resdata = data; });
beside these nothing changed, when trying execute code, getting error
$http not defined
in order use $http first need inject controller
var module = angular.module('putnamehere', []) module.controller('myctrl', ['$http', function($http){ //injection here $http({ url: url, method: "get", data: data }).success(function(data, status, headers, config) { resdata = data; }).error(function(data, status, headers, config) { resdata = data; }); }])
Comments
Post a Comment