Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular JS AJAX Call with Parameters

without the parameters of the method Get, the code works, but if the method asks for a parameter an error 404 is returned. How do I properly send parameters with 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; 
    }
like image 956
ElementaryStudentProgramming Avatar asked Mar 26 '14 04:03

ElementaryStudentProgramming


1 Answers

Since it's a GET request you shouldn't be sending data. You need to be sending a query string.

Change your data to params.

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

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

like image 149
Rowan Freeman Avatar answered Sep 18 '22 18:09

Rowan Freeman