This project is read-only.

How to fix Ajax call Issue?

Nov 18, 2014 at 2:14 PM
Hi all,

I have added online users count in NearForum forum application. In this i have added a javascript function to made Ajax call on every 30 seconds once to Action in AuthenticationController .

I have added these lines of code in AuthenticationController

[HttpPost]
    public ActionResult OnlineUsers(string getCount)
    {
        var usersCount = _service.GetOnlineUsersCount();
        return Json(usersCount, JsonRequestBehavior.AllowGet);
    }
I did't get any compilation errors, but when running follwing error occurs in AJAX call http://localhost:394/Authentication/OnlineUsers Failed to load resource: the server responded with a status of 405 (Method Not Allowed).


Script Code:

$.ajax({
        url: '/Authentication/OnlineUsers',
        type: 'post',
        data: '',
        contentType: 'application/json',
        success: function (data) {
          console.log((data);

        },
        error: function (xhr) {
            console.log("Error in Ajax Call,Please try Later");
        }

    });

Please help me to find out the solution.

Thanks in Advance.