简体   繁体   中英

Jquery Ajax Always Error is trigerred

I don't understand why my custom callback error function is always triggered. If I remove this callback function, my success callback function is triggered.

I read on internet that this a encoding problem but in my case, I don't believe so.

Here my code :

In client

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()
        }
    }
}

In my server :

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

What am I doing wrong?

myError("Error") . Here you are ACTUALLY calling it. You do not need to pass in an argument. functionName() actually calls it. Just pass myError

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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