我正在嘗試AJAX Webservice在 VB ASP.NET 頁面上運行請求。
當頁面加載時,我試圖呼叫網路服務,但500在控制臺中出現錯誤。
我的 WebService 檔案如下所示:
<System.Web.Script.Services.ScriptService()>
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")>
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
<ToolboxItem(False)>
Public Class usrDataSave
Inherits System.Web.Services.WebService
<WebMethod()>
Public Function saydata(abc As String)
MsgBox(abc)
Return abc
End Function
我的 ASP.NET 頁面如下所示:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "POST",
url: "usrDataSave.asmx/saydata",
data: "hello_world",
contentType: "application/json",
datatype: "json",
success: function(responseFromServer) {
alert(responseFromServer.d)
}
});
});
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
我希望頁面加載并彈出服務器端的訊息框,上面寫著“hello_world”,以及 Web 瀏覽器來創建一個顯示相同內容的彈出視窗。但是,這不會發生,因為我收到了 500 錯誤。
我試圖通過使用不同版本的jQuery以及在web.config檔案中啟用請求來解決這個問題,如下所示:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
這不起作用,我仍然在 Web 瀏覽器控制臺中得到“服務器回應狀態為 500”的資訊。應用程式的除錯控制臺中不會記錄任何錯誤。
我怎樣才能解決這個問題?
uj5u.com熱心網友回復:
好的,假設兩個頁面都在同一檔案夾中 - 在同一級別?
那么這應該有效:
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: usrDataSave.asmx/saydata
data: "{abc: 'hello_world'}",
contentType: "application/json",
datatype: "json",
success: function (responseFromServer) {
alert(responseFromServer.d)
}
});
});
</script>
請注意您的資料如何與您的引數匹配..
所以,假設你有這個:
<WebMethod()>
Public Function saydata(abc As String, def as string) as string
MsgBox(abc)
Return abc & " " & def
End Function
并注意我們如何將函式設定為字串——你應該給函式一個型別——在這種情況下是“字串”。
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "WebService1.asmx/saydata",
data: "{abc: 'hello', def: 'world'}",
contentType: "application/json",
datatype: "json",
success: function (responseFromServer) {
alert(responseFromServer.d)
}
});
});
</script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/395012.html
標籤:javascript 查询 网站 阿贾克斯 网络
上一篇:使用影像URL回圈訪問資料庫,服務器錯誤地解釋檔案路徑
下一篇:在舊版ASP.NET網站專案中,我應該在哪里定義MembershipValidatePasswordEventHandler?
