Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Sunday, December 28, 2014

How to Call Asp.net C# Method/Function Using jQuery Ajax

Call Asp.net C# Method/Function Using jQuery Ajax:



In this post  we are try to implement how to  use an ajax method to call C# web method. We can use ajax with PHP or with ASP.NET or many other technologies. Now we will see How to Call C# Method/Function Using jQuery Ajax.Ajax is a group of interrelated Web development techniques used on the client-side to create asynchronous Web applications.

Call function in C# Code :

With the help of the jQuery.ajax() or $.ajax() we can able to call the web method which is defined in our c# class. $.ajax() function will make a asynchronous HTTP(Ajax) request to our web method called as MYSampleAjaxCall. In order to make a asynchronous HTTP request using $.ajax() function we have to pass some parameters, we will see them one by one.

<script type="text/javascript">

$(document).ready(function () {


var Firstname= $(“#txtfirstname”).val();

var Lastname=$(“#txtlastname”).val();


$.ajax({

type:"POST",

url:"splessonsReegistration.aspx/MYSampleAjaxCall",

data:' {FName:"'+Firstname+'",LName:"'+Lastname+'"}',

ContentType:"application/Json;Charset=utf-8",

datatype:"Json";

Success:OnSuccess;

Failure:Function(responce){

alert(responce.d);

}

}); 

});



Function OnSuccess(responce){

alert(responce.d);

}

</script>



Asp.net Related Other Post:


No comments:

Post a Comment