weixin_33736832 2017-10-25 20:45 采纳率: 0%
浏览 34

Alfresco网页脚本:AJAX,JSON

I've successfully created a webscript to that returns a JSON response. See below:

get.js file:

// search for folder within Alfresco content repository
var folder = roothome.childByNamePath("PATH");

// validate that folder has been found
if (folder == undefined || !folder.isContainer) {
   status.code = 404;
   status.message = "Folder " + " not found.";
   status.redirect = true;
}

// construct model for response template to render
model.folder = folder; 

get.json.ftl:

{"corporates" : [
     <@recurse_macro node=folder depth=0/>
     ]
}

<#macro recurse_macro node depth>
     <#list node.children?sort_by(["properties","name"]) as child>
          {
          "Name" : "${child.properties.name}",
          "URL" : "${child.url}",
          "serviceURL" : "${child.serviceUrl}",
          "shareURL" : "${child.shareUrl}",
          "ID" : "${child.id}",
          "Type" : "${child.typeShort}"
          },
          <#if child.isContainer>
          {
               <@recurse_macro node=child depth=depth+1/>
          }
          </#if>
     </#list>
</#macro>

This returns JSON cleanly (woohoo!), but I would like to grab the JSON from a second webscript using AJAX.

Currently, I am utilizing a typical AJAX call in my second webscript's get.html.ftl file like this:

$(document).ready(function() {
    $('.submit-button').click(function(e) {

  // Avoid to trigger the default action of the event.
  e.preventDefault();

  // Actions declared here...
  $.ajax({
      type: 'GET',
      dataType: 'html',
      url: 'PLACEHOLDER_URL_PATH',
      success: function(data) {

        // Shows the result into the result panel.
        $('#alfresco-result').html(data);
        alert('Done.');

      },
      error: function(data) {

        // Shows the result into the result panel.
        $('#alfresco-result').html("ERROR");
        }
    });
});
})

My question is why the AJAX call doesn't work when I use dataType: 'json'?

I would like to parse through the JSON in my AJAX call and turn it into html (e.g. an html list), but it's not accepting the JSON dataType as an acceptable input.

Any help is appreciated!

  • 写回答

1条回答 默认 最新

  • weixin_33698823 2017-10-26 05:27
    关注

    You can use POST Webscript Call using ajax like this and pass your jsonObject

    dataObj:"yourJsonObject",

    to dataObject

    Alfresco.util.Ajax.jsonPost(
    
    {
                url: Alfresco.constants.PROXY_URI + "sample/mypostwebscript",
    
                dataObj:"yourJsonObject",
    
                successCallback: {
    
                                fn: function(res){
    
                                   alert("success");
    
                                   alert(res.responseText);                                                                                            
    
                                },
    
                                scope: this
    
                },
    
                                failureCallback:
    
                                {
    
                                   fn: function(response)
    
                                   {
    
                                                  // Display error message and reload
    
                                                  Alfresco.util.PopupManager.displayPrompt(
    
                                                  {
    
                                                                 title: Alfresco.util.message("message.failure", this.name),
    
                                                                 text: "search failed"
    
                                                  });                                          
    
                                   },
    
                                       scope: this
    
                                    }
    
    });
    
    },
    
    评论

报告相同问题?

悬赏问题

  • ¥15 鸿业暖通修改详细负荷时闪退
  • ¥15 有偿求码,CNN+LSTM实现单通道脑电信号EEG的睡眠分期评估
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体