Angular JS AJAX Call with options

without Get method parameters, the code works, but if the method requests a parameter, error 404 is returned. How to send parameters correctly using Angular JS?

factory.test = function () { var q = $q.defer(); $http({ method: "GET", url: url + "/dataEntry/test", data: { sampletext : "sample" } }) .success(function (data, status, headers, config) { q.resolve(data); }) .error(function (data, status, headers, config) { q.reject(data); }); return q.promise; }; 

  [Route("test")] public String Get(string sampletext) { return "Reply coming from data entry controller" + sampletext; } 
+7
javascript angularjs ajax parameters asp.net-mvc
source share
2 answers

Since this is a GET request, you should not send data. You need to send a query string.

Change data to params .

 $http({ method: "GET", url: url + "/dataEntry/test", params: { sampletext : "sample" } }) 

Source: http://docs.angularjs.org/api/ng/service/$http

+15
source share
 $http({ url: "/saveInfo", method: 'Post' }).then(function(response) { console.log("saved successfully"); }, function(response) { console.log("Error message"); }); 
-2
source share

All Articles