簡體   English   中英

使用WebService從MasterPage調用Ajax

[英]Call Ajax from MasterPage with WebService

我正在嘗試通過Ajax從母版頁調用方法而沒有成功:

母版頁

$(function ListaCategorias() {
        var pageUrl = '<%=ResolveUrl("~/WebService/MenuEsquerdo.asmx")%>';

        $.ajax({
            type: "POST",
            url: pageUrl + '/ListaCategoriasMenu',
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataTyle: "json",
            async: false,
            error: function (jqXhR, textStatus, errorThrown) { alert(errorThrown); },
            success: function (data) {
                var Categorias = data.d;
                var counter = 0;

                aCategorias = [];

                //Carrega as Categorias
                $.each(Categorias, function (index, categorias) {
                    aCategorias[counter] = [
                        categorias.cat_id, categorias.cat_descricao, categorias.cat_total_anuncios
                    ];
                    counter++;
                });
            }
        });
    });

MenuEsquerdo.asmx

/// <summary>
/// Summary description for MenuEsquerdo
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class MenuEsquerdo : System.Web.Services.WebService
{

    [WebMethod]
    //[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static IList ListaCategoriasMenu()
    {
        tab_categorias tabCategorias = new tab_categorias { cat_ativo = true, cat_deletado = false };
        var listCategorias = tabCategorias.ListaCategoriasMenu();

        return listCategorias;
    }
}

我剛收到錯誤消息“內部服務器錯誤”。

我究竟做錯了什么?

我想加載一個我認為在使用WebService時使用的菜單,但是如果您知道更好的選項(例如事件處理程序),我會開放的。

謝謝。

更新

我也嘗試使用用戶控件,但是返回的錯誤消息是Forbbiden!

您的ListaCategoriasMethod()是靜態的Web方法,而這些方法在Web服務中不起作用。 檢查此Stackoverflow問題, 為什么在ASMX Web Services中不能將靜態方法用作Web Service操作? 更多細節。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM