AJAX to web method not returning JSON

人盡茶涼 提交于 2019-12-02 06:18:16

Try this

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string CustomOrderService(string id)
        {
            string result;
            // code logic which sets the result value
            result="some value";

            return result;
        }

Decorate your CustomOrderService method with:

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]

Also, change your return data to:

return new JavaScriptSerializer().Serialize(result);

The only thing I see missing is making the method static.

read this article

http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

Use Static String.

    [WebMethod]
    public static string CustomOrderService(string id)
    {
        string result;
        // code logic which sets the result value
        result="some value";

        return result;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!