简体   繁体   English

成功,失败不称为C#函数的Ajax调用

[英]Success, failure not called Ajax call to C# function

I've been sitting on a problem and I can't figure out why the problem is even there. 我一直坐在一个问题上,但我不知道为什么问题仍然存在。

The problem is that I'm calling C# function via Ajax post. 问题是我通过Ajax发布调用C#函数。

The javascript code is javascript代码是

$.ajax({
    type: "GET",
    url: "Home/LogIn",
    data: { userName: username, password: password },
    dataType: 'json',
    succes: function (data) {
        alert(data.d + '  Succes')
    },
    failure: function (data) {
        alert(data.d + '  failure');
    }
});

And the C# function code is C#功能代码是

public string LogIn(string userName, string password)
{
    LogInController loginController = (LogInController)Session["LogInController"];

    User tempuser = loginController.CheckLogin(password, userName);

    if (tempuser != null)
    {
        massdrop = new MassdropShop(tempuser);
        Session["LoggedInName"] = tempuser.Name;
        Session["massdrop"] = massdrop;
        return "1";
    }
    else
        return "0";
}

When I run this code, it triggers the C# function, the C# function does it's job and everything's fine. 当我运行此代码时,它将触发C#函数,C#函数可以完成工作,一切都很好。 But for some reason the Success and Failure function aren't running. 但是由于某种原因,成功和失败功能未运行。

Is there anyone who could enlighten me to what I'm doing wrong? 有谁能启发我做错了什么?

Greetings, 问候,

Bram 布拉姆

Try success instead of succes . 尝试success而不是succes I've had the same issue 我有同样的问题

        succes: function (data) {
        alert(data.d + '  Succes')
    },

should be 应该

    success: function (data) {
        alert(data.d + '  Succes')
    },

Hope this solves the problem, if not comment and I'll take a closer look at it! 希望这能解决问题,如果不发表评论,我将仔细研究它!

try this in this line 在这一行尝试一下

data:{ userName: username, password: password },

change
data:JSON.stringify{ userName: username, password: password },
success: function (data) {


            alert(JSON.stringify(data.d));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM