1

I'm trying call by Ajax a method from a masterpage without success:

MasterPage

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

I just get the error message "Internal Server Error".

What am I doing wrong?

I want to load a menu I thought in use a WebService but if you know a better option like event handler I'm open minded.

Thanks.

UPDATE

I also tryied to use a User Control, but the error message returned is Forbbiden!

Willian
  • 95
  • 10

1 Answers1

0

Your ListaCategoriasMethod() is a static web method, and those don't work in a web service. Check this Stackoverflow question Why are Static Methods not Usable as Web Service Operations in ASMX Web Services? for more details.

Community
  • 1
  • 1
jjokela
  • 337
  • 2
  • 8