0

Why in function Login(string email,string password) email is null and password also null.

JavaScript:

$http({
      method: "GET",
      url: '/Home/Login/',
      dataType: "json",
      params: JSON.stringify({ email: 'Test', password: 'Test' })
}).success(function (data, status, headers, config) {
      alert(data);
});

HomeController:

    public JsonResult Login(string email,string password)
    {
        return Json("working",JsonRequestBehavior.AllowGet);
    }
1
  • 3
    Why are you still using the .success() callback? Commented May 9, 2016 at 7:05

1 Answer 1

3

Your server expecting the params as query parameters but you are sending as JSON string. Change your line

params: JSON.stringify({ email: 'Test', password: 'Test' })

to

params: { email: 'Test', password: 'Test' }

And remove dataType: "json",

Tip: Like @Phil & @Sateh mentioned, don't use success or error methods instead use then method. So your code will look like this:

$http({
      method: "GET",
      url: '/Home/Login/',
      params: { email: 'Test', password: 'Test' }
}).then(function(response) {
      alert(response.data);
}, function() {
      console.log("Error occured");
});
Sign up to request clarification or add additional context in comments.

1 Comment

You can't just replace .success() and .error() with the same callbacks in then(). The argument to each is entirely different; it's the full response object, not just the data

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.