AnsweredAssumed Answered

Consume a external JSon

Question asked by lgonzalez on Nov 5, 2014
Hello everyone,

Well, i want to consume a external json, and put the data into a dashlet

Here it's the code, if you can help i realy appreaciate

<code>

file HelloWorld.get.html.ftl
<#assign el = args.htmlid>

<div class="hello user dashlet">
        <div class="title" id="greeting_div">Helloworld Dashlet </div>
                <div class="body" id ="$(el)_result">
                        <h2> ${greeting} ${user.id} </h2>
                </div>
        </div>
—————————————————————–
file HelloWorld.get.desc.xml

<webscript>
        <shortname>Hello World Dashlet </shortname>
        <description>Display Greetings</description>
        <family>user-dashlet</family>
        <url>/components/dashlets/HelloWorldDashlet</url>
        <format default="json">extension</format>
</webscript>

———————————————————

file HelloWorld.get.json.ftl

{
"id":"${data.id}",
"name":"${data.name}",
"email":"${data.email}",
"fact":"${data.fact}"
}
——————————————————

file HelloWorld.get.js
function main()
{
        model.greeting = "Welcome"
        model.user = user.name

        var uri = "http://localhost/sietApi/index.php/api/example/user/id/1/format/json",
         connector = remote.connect("http"),
         result = connector.get(uri);
      if (result.status == status.STATUS_OK)
      {
         var td = eval("(" + result.response + ")");
         model.user = td
      }
}
main()

<code>

Outcomes