This function is an easy way to call a URL and receive an evaluated JSON response. You can pass POST data to the server either as a parsed JSON object or as a raw POST buffer.

JSON Parameter (just pass a value):

function CallService() { ajaxJson("services/timetrakkerservice.svc/LoadCustomer", {Pk:12,Entered:new Date()}, function (result) // parsed object instance { alert( result.d.Company); alert( result.d.ProjectEntities[1].CustomerEntity.LastName); },onError); function onError(error) // error object { alert("Error: " + error.message); }

Raw POST data:

function CallService() { ajaxJson("services/timetrakkerservice.svc/SaveCustomer", "Name=Rick&Company=West+Wind", Callback,onError, { contentType: "application/x-www-urlencoded"}); } function Callback(result) { alert( result.d.Company); alert( result.d.ProjectEntities[1].CustomerEntity.LastName); } function onError(error) { alert("Error: " + error.message); }

Note that if passing a string you should pass the content type explicitly - otherwise the string will be posted as JSON.

If you are calling a CallbackHandler or AjaxMethodCallback control on the server use the ajaxCallMethod function instead.