I'm trying to use jQuery to get data from an ASP.NET web service (SharePoint Server 2007 lists.asmx), but any call to a web service will really help as a first step in that direction.
Server To Client (ASP.NET MVC) Firstly, add jQuery CDN (Content Delivery Network) reference which loads jQuery library. Second, the code block to get list of employee from Server and display it. Here, this method type is "GET", gets data in success properties as response parameter.
Can we call C# code behind using jQuery? we can but we need to specify the backend method as static . Yes,But it having some prerequisiteC# method mark as webmethod.
I use this method as a wrapper so that I can send parameters. Also using the variables in the top of the method allows it to be minimized at a higher ratio and allows for some code reuse if making multiple similar calls.
function InfoByDate(sDate, eDate){ var divToBeWorkedOn = "#AjaxPlaceHolder"; var webMethod = "http://MyWebService/Web.asmx/GetInfoByDates"; var parameters = "{'sDate':'" + sDate + "','eDate':'" + eDate + "'}"; $.ajax({ type: "POST", url: webMethod, data: parameters, contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { $(divToBeWorkedOn).html(msg.d); }, error: function(e){ $(divToBeWorkedOn).html("Unavailable"); } }); }
I hope that helps.
Please note that this requires the 3.5 framework to expose JSON webmethods that can be consumed in this manner.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With