Jquery Ajax Always Error是trigerred

时间:2017-03-25 13:47:36

标签: javascript jquery ajax

我不明白为什么我的自定义回调错误功能总是被触发。 如果我删除此回调函数,则会触发我的成功回调函数。

我在网上看到这是一个编码问题但在我的情况下,我不相信。

这是我的代码:

在客户端

myFunction = function () {

    $.ajax({
        url: customUrl,
        type: "POST",
        data: JSON.stringify(buildDatata("custom")),
        contentType: "application/json",
        dataType: "json",
        success: mysuccess,
        error: myerror("Error")
    });
}

buildDatata= function (action) {
    return data = {
        "Action": action,
        "SubscriptionInfo":
        {
            "SiteId": CurrentSiteId,
            "WebId": CurrentWebId,
            "ListId": CurrentListId,
            "ItemId": CurrentItemUniqueId,
            "SubscriptionDate": new Date().toUTCString(),
            "SubscriptionType": GetTypePage()
        }
    }
}

在我的服务器中:

private void HasSubscripted(HttpContext context, BookmarkAction bookmarkAction)
        {

            bool result  = true;

            SendResponse(context,
                new
                {
                    isSubscripted = result
                }
            );

        }

protected void SendResponse(HttpContext context, object jsonResponse)
        {
            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();

            context.Response.Clear();
            context.Response.ContentType = "application/json";
            context.Response.Write(jsonSerializer.Serialize(jsonResponse));
            context.Response.End();
        }

我做错了什么?

1 个答案:

答案 0 :(得分:1)

myError("Error")。在这里你实际上是在呼唤它。你不需要传递参数。 functionName()实际上称之为。只需通过myError