Web方法无法找到页面aspx

时间:2017-10-16 07:48:41

标签: javascript jquery asp.net vb.net

我有这个HTML标记

 <asp:DropDownList ID="ddlCustomers" runat="server">

ASP.Net DropDownList项(选项)将通过在ASP.Net中使用jQuery AJAX调用WebMethod以JSON格式从数据库中获取数据来填充。

使用jQuery的客户端

$(document).ready(function () {
$.ajax({
    type: "POST",
    url: "Regione.aspx/GetRegioni",
   data: '{}',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (r) {
        var ddlCustomers = $("[id*=ddlCustomers]");
        ddlCustomers.empty().append('<option selected="selected" value="0">Please select</option>');
        $.each(r.d, function () {
            ddlCustomers.append($("<option></option>").val(this['Value']).html(this['Text']));
        });
    }
});

})

VB:NET

Imports System.Data
Imports System.Web.Services
Imports System.Configuration
Imports System.Data.SqlClient

 <System.Web.Services.WebMethod()>
    Public Shared Function GetRegioni() As List(Of ListItem)
        Dim query As String = "SELECT IDRegione, NomeRegione FROM TB_REGIONI"
        Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
        Using con As New SqlConnection(constr)
            Using cmd As New SqlCommand(query)
                Dim regioni As New List(Of ListItem)()
                cmd.CommandType = CommandType.Text
                cmd.Connection = con
                con.Open()
                Using sdr As SqlDataReader = cmd.ExecuteReader()
                    While sdr.Read()
                        regioni.Add(New ListItem() With {
                          .Value = sdr("IDRegione").ToString(),
                          .Text = sdr("NomeRegione").ToString()
                        })
                    End While
                End Using
                con.Close()
                Return regioni
            End Using
        End Using
    End Function

当我运行代码时出现此错误:&#34; jquery.min.js:2 POST http://localhost:65122/GetRegioni/Regione.aspx 404(未找到)&#34;

哪里可能是错误?我找不到了。

0 个答案:

没有答案