7

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; 
    }
2
  • What is your backed ? ASP.Net MVC ? Commented Mar 26, 2014 at 4:20
  • Yes it is. ASP .Net MVC Commented Mar 26, 2014 at 4:24

2 Answers 2

15

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.