从 $.getJSON 方法读取数据

Reading Data from $.getJSON Method

我正在尝试使用 $.getJSON 方法来使用 REST API。 我得到了所需的 JSON 输出,但没有在方法的输出(结果变量)中进行处理。警报消息也没有到来。它只是空白输出。 请找到附件中的代码和图像(包含我在浏览器的开发者工具中需要的响应输出)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 response return Json 然后您可以使用 $.getJSON。由于您尚未添加 API 代码,我相信它不会返回 JSON response。如果不是 JSON response 那么你可以使用 $.get 就可以了。