gpt4 book ai didi

javascript - Jquery ajax函数调用vb文件中的代码

转载 作者:行者123 更新时间:2023-12-03 02:21:40 27 4
gpt4 key购买 nike

首先,我想做的是填充一个下拉框,如下所示:

<asp:DropDownList CssClass="ui dropdown" ID="drpGolfClub" runat="server"></asp:DropDownList>

一些值给了我高尔夫俱乐部 ID 和名称。问题是,使用 jQuery 我似乎无法运行后面的 vb 文件中的代码。一切看起来都是这样的。在 aspx 文件中:

 function loadGolfClub()
{
alert('inside method');
//debugger;
$.ajax({
type: "POST",
url: "Register.aspx/LoadGolfClub",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (Result) {

debugger;
Result = Result.d;
$('#<%=drpGolfClub.ClientID%>').empty();
$('#<%=drpGolfClub.ClientID%>').prepend("<option value='0'>" +"Select" + "</option>");
$.each(Result, function (key, value) {
$('#<%=drpGolfClub.ClientID%>').append($("<option></option>").val(value.GolfClubId).html(value.GolfClubName));
$('#<%=drpGolfClub.ClientID%>')[0].selectedIndex = 1;
});
alert("in sucess!");
},

failure: function () {
alert("Failed!");
}
});
}

aspx文件后面的vb是这样添加的:

Imports System
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports Owin
Imports System.Data
Imports System.Web.Services
Imports System.Reflection
Imports Golfbook.CoreLibrary
Imports Golfbook.CoreLibrary.Golfbook.Services


Public Class Register
Inherits System.Web.UI.Page
Shared objGCBO As New GolfClubBO()

Shared objGolfClubService As New Golfbook.CoreLibrary.Golfbook.Services.GolfClub.GolfClubDetails

Shared details As New List(Of GolfClubBO)()
Shared _loginName As String
Shared loginName As String

Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

End Sub

<WebMethod()>
<System.Web.Script.Services.ScriptMethod(ResponseFormat:=System.Web.Script.Services.ResponseFormat.Json)>
Public Shared Function LoadGolfClub() As GolfClubBO()
Dim details As New List(Of GolfClubBO)()
Try
details = objGolfClubService.LoadGolfClub()
Catch ex As Exception

End Try
Return details.ToList.ToArray()
End Function
End Class

我知道vb中的page_load已运行,但它永远不会进入那里的函数。我现在已经尝试了“一切”,但不知道该怎么做。函数中添加的警报框正在触发,因此它开始运行

我知道 JQuery 正在工作,因为我已将一些值添加到随机文本框中:$('#txtFirstName').val('Martin');

有什么提示可以解释这可能是什么原因吗?

最佳答案

如上所述,感谢 ADyson,解决我的问题的答案是解决这个问题:在 ~/App_Start/RouteConfig.cs 内更改:

settings.AutoRedirectMode = RedirectMode.Permanent;
To:

settings.AutoRedirectMode = RedirectMode.Off;

谢谢大家的回复!

关于javascript - Jquery ajax函数调用vb文件中的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49131496/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com