I have been able to call the function using ajax using following code
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?";
}
But if i don't have any .aspx
page, i have only .html page with a class say myfunclass.cs
. How do i call the same function from here. I have tried but fail
$.ajax(
{
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'myfunclass.cs/Server_HelloWorld',
datatype: 'json',
success: function (result) { alert(result.d); }
})
You cant just call *.cs file. You need to create some backend, like ASP.NET MVC Web API like in example here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.