简体   繁体   English

使用jQuery进行API Rest调用

[英]Making API Rest call using jQuery

I'm trying to make a REST call from jquery to a rest service. 我正在尝试从jQuery到REST服务进行REST调用。 I am going to consume data from OpenMRS API . 我将使用OpenMRS API的数据。 I was following the instructors of this post. 我一直在关注这个职位的老师。

Now, I made the call , but still stacking with parsing the object to Json and showing it on the HTML Page. 现在,我进行了调用,但是仍然与将对象解析为Json并将其显​​示在HTML Page上堆叠在一起。 I got problems in doing that. 我这样做有问题。 I am sharing code on this JSFiddle. 我正在 JSFiddle上共享代码。

What are the different steps to parse JSon response ? 解析JSon响应有哪些不同的步骤?

To explore the object , I am using Chrome Console. 要浏览该对象,我正在使用Chrome控制台。 I wrote this line as an example of can I consume data (Observation in this case): 我写此行作为我可以消费数据的示例(在这种情况下为观察):

 `$('#result').html('<p>' + data[0].concept +  '<p>');`

' '

In your example data is already an object. 在您的示例中,数据已经是一个对象。 Si you just navigate through it like any other object; 您只是像其他任何对象一样浏览它;

ex: 例如:

$('#result').html('<p>' + data.results[0].concept.display +  '<p>');

On the js put : 在js上放:

success: function (data) {
            console.log(data);

So you can use the chrome console to see how the object is made. 因此,您可以使用chrome控制台查看对象的制作方式。 Below a partial exemple of the console.log output: 下面是console.log输出的部分示例:

Object {results: Array[15]}
results: Array[15]
0: Object
accessionNumber: null
comment: null
concept: Object
display: "Patient Record Image"
links: Array[1]
uuid: "raxa00000-0000-0000-0000-000000000023"
__proto__: Object

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM