Created
September 2, 2019 08:04
-
-
Save ankitkanojia/caf7a871e8030483d6ecba7b134ee973 to your computer and use it in GitHub Desktop.
call web method using ajax call in webform c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
public partial class _Default : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
} | |
[System.Web.Services.WebMethod] | |
public static void FunctionName() | |
{ | |
try | |
{ | |
//C# function code | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script> | |
function functionName(){ | |
$.ajax({ | |
type: "POST", | |
url: "Default.aspx/FunctionName", | |
data: '{parameterName: "' + parameterValue + '"', | |
contentType: "application/json; charset=utf-8", | |
dataType: "json", | |
success: function (response) { | |
//success return | |
}, | |
failure: function (response) { | |
//error return | |
} | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment