I am not able to get response as json. pls help me out.

Posted by Christxavier under ASP.NET MVC on 9/13/2013 | Points: 10 | Views : 2192 | Status : [Member] | Replies : 1
hi, i created one wep api crud operation using MVC. i followed this following link to create that web api. kindly go through this link for clear.


I got the GET response also. but i am getting xml response. instead i needed json response. so in that article they told to put following javascript to get JSON response but they did not mention where to put the following javascript. so blindly i put the javascript in index.cshtml<--views<---HOME(which is in solution explorer in project). because this folder only has design form. so still i am getting xml response. if i remove the javascript also, it response xml format. so, i think the javascript is not invoked or i do not know where to put the javascript correctly. so, please help from this problem. thanks a lot.

javascript file:

<script type="text/javascript">
$(document).ready(function () {


type: "GET",
url: "api/customer/1",
dataType: "json",
success: function (data) {

output file:

<CustomerModel></div> <div class="collapsible-content"> <div class="line"><Id>1</Id></div> <div class="line"><Salary>20</Salary></div> <div class="line"><cusName>rajesh</cusName></div> </div> <div class="line"></CustomerModel></div> </div> </div> <div class="collapsible" id="collapsible2"> <div class="expanded"> <div class="line"><CustomerModel></div> <div class="collapsible-content"> <div class="line"><Id>2</Id></div> <div class="line"><Salary>50</Salary></div> <div class="line"><cusName>magesh</cusName></div> </div> <div class="line"></CustomerModel></div> </div> </div> </div> <div class="line"></ArrayOfCustomerModel></div>


Posted by: Jayakumars on: 9/13/2013 [Member] [MVP] Bronze | Points: 25


post your code zip format.

Mark as Answer if its helpful to you


Christxavier, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response