javascript - Jquery Ajax 总是触发错误

标签 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();
        }

我做错了什么?

最佳答案

myError("错误")。在这里你实际上是在调用它。您不需要传递参数。 functionName() 实际上调用了它。只需传递 myError

关于javascript - Jquery Ajax 总是触发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43017150/

相关文章:

Javascript/HTML - 隐藏 DIV 直到单击按钮

jquery - 在 MeteorJS 中为表格行制作动画

javascript - 如何每 5 秒更新一次传单标记

jquery - CakePHP + ajaxForm - 加载 View 的一部分

javascript - 同步/异步 AJAX 功能模式

javascript - 如何从 forEach 方法中删除不需要的计数增量?

javascript - 在javascript中格式化小数

javascript - Angularjs函数从另一个函数调用并等待其响应

javascript - Galleria 的箭头控制

jquery - 使用 jquery 进行多个 ajax 请求