我正在尝试通过 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!