?Briella 2014-02-13 00:17 采纳率: 0%
浏览 15

queryformat和Railo

Apologies if I'm haven't found it in the documentation yet...

Q: How do you change the queryformat for an ajax call in Railo? Here's my component:

component {

    remote function Read() returnformat='json' {
        svc = new Query();
        svc.setSQL("SELECT * FROM INFORMATION_SCHEMA.TABLES");
        obj = svc.execute();
        local.result.Prefix = obj.getPrefix();
        local.result.qry = obj.getResult();
        url.queryFormat = "column";
        return local.result;
    }
    }

and here's my JavaScript:

(function() {
    var local = {};

    local.type = 'POST';
    local.url = 'AJAX.cfc';
    local.dataType = 'json';
    local.data = {};
    local.data.method = 'Read';
    local.Promise = $.ajax(local);
    local.Promise.done(done);
    local.Promise.fail(fail);

    function done(response) {
        console.log(response);
        debugger;
    }
    function fail(xhr,status,response) {
        debugger;
    }
})();

What I'm getting back is:

response.qry.DATA[] // 57 arrays, each of length 4

But ColdFusion returns this, which I've grown fond of using (being able to use the column names instead of the array position):

response.qry.DATA.TABLE_CATALOG[] // An array of 57 elements
response.qry.DATA.TABLE_SCHEMA[]
response.qry.DATA.TABLE_NAME[]
response.qry.DATA.TABLE_TYPE[]
  • 写回答

1条回答 默认 最新

  • weixin_33714884 2014-02-13 19:41
    关注

    Use ReturnFormat="plain" on the function, and pass true for the 2nd argument of serializeJson()

    serializeJson(Query, true)
    

    That will give you a JSON object that is serialized by Column, so you can just return it.

    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备