Saturday, April 3, 2010

Linq to Json

var q = from b in data.napps2_price_categories
where b.Lang == lang
orderby b.Description
select new { b.Code, b.Description };
return (JsonConvert.SerializeObject(q));

Returns the results as JSON
JSON.NET

Calling the webservice from javasacript via JQuery

$.ajax({
type: "POST",
url: "/WebServics/DoStuff.asmx/Functionname",
data: "{'lang': 'EN'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
AjaxSucceeded(msg);
},
error: AjaxFailed
});

function AjaxSucceeded(result) {
eval('var jsonvar = ' + result.d);
for (var i = 0; i < jsonvar.length; i++)
$('#divCategory').append('');
}

No comments:

Post a Comment