This function provides an easy way to call an HTTP url that takes a JSON input and returns a JSON response. The method automatically parses a parameter object to JSON and result JSON into a result object or value.

You can pass a value or object that is turned into JSON which by default is POST'ed to the server. If no parameter is provide the request defaults to a GET operation. You can override the verb via the options.verb parameter. You can also use the options.noPostEncoding option to prevent JSON encoding of parameters.

The result is handled either via the two callback parameters for success and error respectively, or via a returned jQuery Promise object.

To call a service with a Promise:

JSON Object or value (just pass a value):

function CallServiceWithPromise()
			{Pk:12,Entered:new Date()},{verb: PUT})
		.then(function (result)  { // parsed object instance
		    alert( result.d.Company);
		    alert( result.d.ProjectEntities[1].CustomerEntity.LastName);

function onError(error)  // error object
    alert("Error: " + error.message); // parsed error

Or call with callback methods:

Raw POST string:

function CallServiceWithCallbacks()
			{ contentType: "application/x-www-urlencoded", noPostEncoding: true});
function Callback(result)
    alert( result.d.Company);
    alert( result.d.ProjectEntities[1].CustomerEntity.LastName);
function onError(error)
    alert("Error: " + error.message);

Alternately, ajaxJson() c

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.


Return Value

jQuery Promise Object


The URL to access including any query string data.

a single value or array that is passed to the server. For MS Ajax pass an object with a property for each parameter. For Web Connection pass an array of values one for each parameter.

If this value is null a GET request is sent. If options don't override behavior a POST request is sent when data is provided.

Optional function that is called on a successful callback. Function receives raw HTTP result string as a parameter.

Optional function that is called when an error occurs. Receives a CallbackException object as a parameter that holds exception information.

An optional object map that configures the HTTP operation based on settings of the HttpClient class. If the callBack and errorCallback functions are not provided options can be passed as the 3rd parameter.


  • accepts - accept header content type
  • contentType - request content type
  • noPostEncoding - don't turn parameter to JSON
  • evalResult - don't turn result to JSON
  • isMsAjaxJson - for MS AJAX style calls
  • method - HTTP Verb (POST or GET are defaults)
  • timeout - request timeout

See also:

Using CallbackHandler with REST Calls | ajaxCallMethod

© West Wind Technologies, 1996-2019 • Updated: 10/09/17
Comment or report problem with topic