[英]Call function from class in c# using jquery ajax
我已經能夠使用以下代碼使用ajax調用該函數
function AjaxCall() {
$.ajax(
{
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'Default.aspx/Server_HelloWorld',
datatype: 'json',
success: function (result) { alert(result.d); }
})
}
using System.Web.Services;
using System.Web.Script.Services;
aspx.cs Ajax Webmethod,
[WebMethod]
public String Server_HelloWorld()
{
return "Hello, How are you?";
}
但是,如果我沒有任何.aspx
頁面,那么我只有.html頁面,其類為myfunclass.cs
。 我如何從這里調用相同的功能。 我已經嘗試過但是失敗了
$.ajax(
{
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'myfunclass.cs/Server_HelloWorld',
datatype: 'json',
success: function (result) { alert(result.d); }
})
您不能只調用* .cs文件。 您需要創建一些后端,例如此處示例中的ASP.NET MVC Web API。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.