从$ .getJSON方法读取数据 [英] Reading Data from $.getJSON Method

查看:365
本文介绍了从$ .getJSON方法读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用一个REST API,我使用$ .getJSON方法。
我得到所需的JSON输出,但不是在方法的输出(结果变量)进行处理。此外,警报消息不来。它只是空白输出。
请找到附加的代码和图像(包含我需要在浏览器的开发工具中的响应输出) http://i.stack.imgur.com/9m2VQ.png

I am trying to consume a REST API for which i am using the $.getJSON method. I am getting the required JSON Output, but not in the method's output(in result variable) to process. Also the alert message is not coming. Its just blank output. Please find the attached code and image(Containing the response output which i need in the Developer Tools of the browser)http://i.stack.imgur.com/9m2VQ.png

<body>
<div>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <button onclick="callSAPRestService2()">Click me</button>
    <script>

         function callSAPRestService2() {
              $.getJSON('http://xxxx:8000/sap/bc/zrest_demo?sap-client=200',
                            function (result) {
                                alert(JSON.stringify(result));
                            });
         }
    </script>
</div>


推荐答案

基本上是因为你必须从您的API 响应返回Json ,然后可以使用 $。getJSON 。由于您尚未添加您的 API 代码,我相信它不会返回 JSON响应。如果不是 JSON响应,那么你可以使用 $。get 很好。

Basically its because you have to return Json from your API response and then you can use $.getJSON. Since you haven't added your API code, I believe it isn't returning JSON response. If it is not JSON response then you can use $.get is fine.

这篇关于从$ .getJSON方法读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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