Skip to main content


Showing posts from August, 2009

Using jQuery in to call Page Method(Web Service)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"""><htmlxmlns=""><headrunat="server"><title></title><scriptsrc="Scripts/jquery-1.3.2.js"type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $("#btnList").click(function() { $.ajax({ type: "POST", url: "Default.aspx/GetList", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { …

How to consume WCF service using JQuery

Create an ASP.NET Web Application (WCF service)Add a new item, aspx page (Default.aspx)You now have an WCF-service with .svc as extension, and that service implements an Interface. It's in the interface we'll set the attributes needed to return JSONCreate a class, Student as below. The attributes "DataContract" and "DataMember" must be defined for the class and the properties that would be returned through the WCF service [DataContract] publicclass Student { [DataMember] publicint StudentId { get; set; } [DataMember] publicstring StudentName { get; set; } [DataMember] publicint Marks1 { get; set; } [DataMember] publicint Marks2 { get; set; } [DataMember] publicstring EmailAddress { get; set; } } Now add a reference to System.ServiceModel.Web this is for WebGet AttributeAdd the WebGet-attribute as specified below. The BodyStyle Bare means "Both requests and responses are not wrapped" - we really want nothing more than a true JSON-respo…