protected void Application_BeginRequest(object sender, EventArgs e){ HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); if (HttpContext.Current.Request.HttpMethod == "OPTIONS") { HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache"); HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST"); HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept"); HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000"); HttpContext.Current.Response.End(); }}
<script type="text/javascript"> $(document).ready(function() { $.ajax({ type: "GET", url: "http://localhost/Service1.svc/GetProductList/", dataType: "xml", success: function(xml) { $(xml).find('Product').each(function() { var id = $(this).find('ProductId').text(); var name = $(this).find('Name').text(); var price = $(this).find('Price').text(); var category = $(this).find('CategoryName').text(); $('<tr><td>' + id + '</td><td>' + name + '</td><td>' + price + '</td><td>' + category + '</td></tr>').appendTo('#products'); }); }, error: function(xhr) { alert(xhr.responseText); } }); });</script>
Login to post response