没有得到响应为JSON [英] Not getting Response as JSON

查看:108
本文介绍了没有得到响应为JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我使用<创建了一个 Wep API CRUD 操作code> MVC 。

我按照以下链接创建了 Web API

请仔细阅读此链接。

MVC 4 WEB API .NET 4.5



我得到 GET 回复也。

但我得到 XML 回复。



相反,我需要 json 回复。因此,在那篇文章中,他们告诉我们将 javaScript 放到 JSON 响应中,但他们没有提到在哪里把以下 javaScript



所以,我盲目地把 javaScript in index.cshtml< - views< --- HOME (在项目中的解决方案资源管理器中)。



因为这个文件夹只有设计形式。所以,我仍然得到 XML 响应。

如果我也删除 javaScript ,它会响应 XML 格式。



所以,我认为 javaScript 没有被调用,或者我不知道在哪里放 javaScript 正确。



所以,请帮助解决这个问题。



非常感谢。



javaScript file:

Hi,

I created one Wep API CRUD operation using MVC.
I followed the following link to create that Web API.
Kindly go through this link for clear.
MVC 4 WEB API .NET 4.5

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 () {
    $.ajax({
        type: "GET",
        url: "api/customer/1",
        dataType: "json",
        success: function (data) {
            alert(data);
        }
    });
});
</script>



输出文件:


output file:

<CustomerModel>
    <Id>1</Id>
    <Salary>20</Salary>
    <cusName>rajesh</cusName>
</CustomerModel>
<CustomerModel>
    <Id>2</Id>
    <Salary>50</Salary>
    <cusName>magesh</cusName>
</CustomerModel>
</ArrayOfCustomerModel>











添加链接文字以反映文章标题。

更正了问题,格式和语法问题的标题。

[/编辑]

推荐答案

(document).ready(function(){
(document).ready(function () {


.ajax({
type: GET
url: api / cust omer / 1
dataType: json
成功:功能(数据){
alert(data);
}
});
});
< / script >
.ajax({ type: "GET", url: "api/customer/1", dataType: "json", success: function (data) { alert(data); } }); }); </script>



输出文件:


output file:

<CustomerModel>
    <Id>1</Id>
    <Salary>20</Salary>
    <cusName>rajesh</cusName>
</CustomerModel>
<CustomerModel>
    <Id>2</Id>
    <Salary>50</Salary>
    <cusName>magesh</cusName>
</CustomerModel>
</ArrayOfCustomerModel>











添加链接文字以反映文章标题。

更正了问题,格式和语法问题的标题。

[/编辑]


看起来只支持xml 。 Json根本就没有。



祝你好运!
Looks like only xml is supported. Json simply isn't.

Good luck!


这篇关于没有得到响应为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆