Handle return data

Syntax

$.response = function (data, callback)

Arguments

data

object

Data received from server.

callback

function

Contains calls of JavaScript functions that should be executed in series if received data is not erroneous.

Description

It evaluates return data from the server whether it contains an error or not. If it contains no error, callback function will be executed, else it will not be executed.

Example

The following program illustrates the function call where a Json String is passed as object for the parameter “data”:

Server:
        public ActionResult Example(string id)
        {
            var model = new ExampleViewModel();
            model.Test(id);
            return Json(new { succeed = true }, JsonRequestBehavior.AllowGet);
        }

Client:
    	 function onTestSuccess(data) { 
            $.response(data, function () { alert(data); }) 
    	 }

The Server returns a Json String. After Client receives the Json String, it forwards it as input for the parameter “data” to the “$.response” function which evaluates it. If the passed Json String contains no error, the “alert” function will output it on the screen.

Last updated