Click below for Step by Step and Interview Q & A (dotnetinter) wrote,
Click below for Step by Step and Interview Q & A
dotnetinter

How can you make a JSON call using Jquery ? ( ASP.Net Jquery interview questions with answers)


Let’s assume you have a MVC controller action “getEmployee” which emits out employee JSON object as shown in the below code. Please note you can always emit JSON from any server technology like WCF , ASP.NET , MVC etc. Do read this link where we have discussed how we can emit JSON data using MVC and WCF. http://questpond.tumblr.com/post/32457322254/json-and-c-interview-questions-what-is-json

p1

To make a call to the above MVC action using Jquery  we need to use “getJSON” method. Below is the simple code for the same. It has three parameters:-

  1. The  first parameter is the URL which emits out JSON. For instance in the below code the URL is “/Employee/getEmployee”.

  2. The next parameter helps us to pass data to the resource which emits out JSON currently it’s the MVC action. Currently we are only doing  a get so the second parameter is NULL for now.

  3. The last parameter is the call back function which will be invoked once the MVC action returns data. You can see how the “getData” function just displays the “empcode” property. Because the output is in JSON it automatically converts the JSON data to javascript object.

p2
Tags: asp.net json, consuming json in jquery interview quest, csharp interview questions, information technology questions, json and jquery interview questions, programming interview questions
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments