文档章节

dreamfactory开源平台的使用

仰望星空
 仰望星空
发布于 2016/06/17 20:59
字数 960
阅读 87
收藏 0

代码如下,感兴趣的可以直接QQ我(744757242):

var DfServer = 'http://192.168.100.216:8888/';
var AppName = 'myApp1';

function getToken() {
    return $.cookie('GEO_Token');
}

function loginUser(name, pwd) {
    var url = DfServer + 'rest/user/session';
    var data = {
        'email': name,
        'password': pwd
    };
    var loginState = false;
    $.ajax({
        dataType: 'json',
        contentType: 'application/json;charset=utf-8',
        url: url,
        data: JSON.stringify(data),
        cache: false,
        async: false,
        type: 'POST',
        headers: {
            "X-DreamFactory-Application-Name": AppName
        },
        success: function (response) {
            $.cookie("GEO_USERNAME", name, { expires: 1, path: '/' });
            $.cookie("GEO_Token", response.session_id, { expires: 1, path: '/' });
            loginState = true;
            $.cookie("first_name", response.first_name, { expires: 1, path: '/' });
            $.cookie("last_name", response.last_name, { expires: 1, path: '/' });
            $.cookie("display_name", response.display_name, { expires: 1, path: '/' });
        },
        error: function (response) {
            var msg = "account erro!";
            if (response.content && response.content.data && response.content.data.error) {
                msg += "detail::" + response.content.data.error[0].message;
            }
            msg = msg.replace(/&quot;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&').replace(/&apos;/g, '\'');
            alert(msg);
        }
    });
    return loginState;
}

function getRecordsByFilter(database, table, filter, success, error, async) {
    var url = DfServer + 'rest/' + database + '/' + table;
    var token = getToken();
    var data = null;
    if (filter == null || filter == "" || filter == undefined)
        data = null;
    else
        data = { filter: filter };
    if (async == null)
        async = false;
    $.ajax({
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        url: url,
        data: data,
        cache: false,
        async: async,
        type: 'GET',
        headers: {
            "X-DreamFactory-Application-Name": AppName,
            "X-DreamFactory-Session-Token": token
        },
        success: function (response) {
            if (typeof success !== 'undefined') {
                success(response);
            }
        },
        error: function (response) {
            var msg = "unknown error!";
            if (response.content && response.content.data && response.content.data.error)
                msg = response.content.data.error[0].message;
            else if (response.responseText)
                msg = JSON.stringify(response.responseText);
            msg = msg.replace(/&quot;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&').replace(/&apos;/g, '\'');
            if (typeof error !== 'undefined' && error) {
                error(msg);
            }
        }
    });
}

function getRecordsByFilterOrder(database, table, filter, order, success, error, async) {
    var url = DfServer + 'rest/' + database + '/' + table;
    var token = getToken();
    var data = null;
    if (!filter)
        filter = "";
    data = { filter: filter, order: order };
    if (async == null)
        async = false;
    $.ajax({
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        url: url,
        data: data,
        cache: false,
        async: async,
        type: 'GET',
        headers: {
            "X-DreamFactory-Application-Name": AppName,
            "X-DreamFactory-Session-Token": token
        },
        success: function (response) {
            if (typeof success !== 'undefined') {
                success(response);
            }
        },
        error: function (response) {
            var msg = "unknown error!";
            if (response.content && response.content.data && response.content.data.error)
                msg = response.content.data.error[0].message;
            else if (response.responseText)
                msg = JSON.stringify(response.responseText);
            msg = msg.replace(/&quot;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&').replace(/&apos;/g, '\'');
            if (typeof error !== 'undefined' && error) {
                error(msg);
            }
        }
    });
}

function getPageRecordsByFilterOrder(database, table, filter, order, limit, offset, success, error, async) {
    var url = DfServer + 'rest/' + database + '/' + table;
    var token = getToken();
    var data = null;
    if (!filter)
        filter = "";
    data = { filter: filter, order: order, include_count: true, limit: limit, offset: offset };
    if (async == null)
        async = false;
    $.ajax({
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        url: url,
        data: data,
        cache: false,
        async: async,
        type: 'GET',
        headers: {
            "X-DreamFactory-Application-Name": AppName,
            "X-DreamFactory-Session-Token": token
        },
        success: function (response) {
            if (typeof success !== 'undefined') {
                success(response);
            }
        },
        error: function (response) {
            var msg = "unknown error!";
            if (response.content && response.content.data && response.content.data.error)
                msg = response.content.data.error[0].message;
            else if (response.responseText)
                msg = JSON.stringify(response.responseText);
            msg = msg.replace(/&quot;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&').replace(/&apos;/g, '\'');
            if (typeof error !== 'undefined' && error) {
                error(msg);
            }
        }
    });
}

function addRecords(database, table, data, success, error, async) {
    var url = DfServer + 'rest/' + database + '/' + table;
    var token = getToken();
    if (data == null || data == "" || typeof data == 'undefined')
        return;
    if (async == null)
        async = false;
    $.ajax({
        dataType: 'json',
        contentType: 'application/json;',
        url: url,
        data: JSON.stringify(data),
        async: async,
        type: 'POST',
        headers: {
            "X-DreamFactory-Application-Name": AppName,
            "X-DreamFactory-Session-Token": token
        },
        success: function (response) {
            if (typeof success !== 'undefined') {
                success(response);
            }
        },
        error: function (response) {
            var msg = "unknown error!";
            if (response.content && response.content.data && response.content.data.error)
                msg = response.content.data.error[0].message;
            else if (response.responseText)
                msg = JSON.stringify(response.responseText);
            msg = msg.replace(/&quot;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&').replace(/&apos;/g, '\'');
            if (typeof error !== 'undefined' && error) {
                error(msg);
            }
        }
    });
}

function updateRecords(database, table, data, success, error, async) {
    var url = DfServer + 'rest/' + database + '/' + table;
    var token = getToken();
    if (data == null || data == "" || typeof data == 'undefined')
        return;
    if (async == null)
        async = false;
    $.ajax({
        dataType: 'json',
        contentType: 'application/json;',
        url: url,
        data: JSON.stringify(data),
        cache: false,
        async: false,
        type: 'PUT',
        headers: {
            "X-DreamFactory-Application-Name": AppName,
            "X-DreamFactory-Session-Token": token
        },
        success: function (response) {
            if (typeof success !== 'undefined') {
                success(response);
            }
        },
        error: function (response) {
            var msg = "unknown error!";
            if (response.content && response.content.data && response.content.data.error)
                msg = response.content.data.error[0].message;
            else if (response.responseText)
                msg = JSON.stringify(response.responseText);
            msg = msg.replace(/&quot;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&').replace(/&apos;/g, '\'');
            if (typeof error !== 'undefined' && error) {
                error(msg);
            }
        }
    });
}

function deleteRecordsByFilter(database, table, filter, success, error, async) {
    var url = DfServer + 'rest/' + database + '/' + table;
    var token = getToken();
    if (filter == null || filter == "" || typeof filter == 'undefined')
        return;
    if (async == null)
        async = false;
    var data = { filter: filter };
    $.ajax({
        dataType: 'json',
        contentType: 'application/json;',
        url: url,
        data: JSON.stringify(data),
        cache: false,
        async: false,
        type: 'DELETE',
        headers: {
            "X-DreamFactory-Application-Name": AppName,
            "X-DreamFactory-Session-Token": token
        },
        success: function (response) {
            if (typeof success !== 'undefined') {
                success(response);
            }
        },
        error: function (response) {
            var msg = "unknown error!";
            if (response.content && response.content.data && response.content.data.error)
                msg = response.content.data.error[0].message;
            else if (response.responseText)
                msg = JSON.stringify(response.responseText);
            msg = msg.replace(/&quot;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&').replace(/&apos;/g, '\'');
            if (typeof error !== 'undefined' && error) {
                error(msg);
            }
        }
    });
}

 

© 著作权归作者所有

共有 人打赏支持
仰望星空

仰望星空

粉丝 2
博文 3
码字总数 2017
作品 1
武汉
产品经理
私信 提问
程序员必看:移动开发中几个全新的开源小工具。

移动优先的开发理念已经成为前瞻性应用开发机构的首要标志。有鉴于此,移动应用开发工具的阵营不断扩张、成员日益丰富自然不足为奇。爱加密小编收集了一部分开发人员的意见,整理了他们对于新...

科技创造
2014/09/09
0
0
Kylin Rest API FOR Java

转 :http://www.cnblogs.com/dreamfactory/p/5588203.html KylinRest 上面这位大神已经写的差不多了,我只是补充一下。 获取API数据的前提需要登录: 这是官网的描述: 这是实现的部分代码 ...

目光
2017/11/07
0
0
开源技术有望改变企业存储发展的未来!

  【IT168 资讯】开源软件一直是推动协作、基于社区的软件的重要力量。其中最明显的例子就是Linux的发展历程,它的各种发行版已经成为云操作系统和现代应用程序开发人员的首选平台。   在...

it168网站
2017/10/09
0
0
介绍几个常见的Git代码托管平台

一、GitHub 目前最流行的Git服务,也是人气最旺盛的Git代码托管网站,好多好的开源项目都来自GitHub,但是GitHub只能新建公开的Git仓库,私有项目需要付费,个人认为GitHub更适合开源项目使用...

学习也休闲
2016/03/03
364
0
书评:《Ours to Hack and to Own》

本书被《连线》杂志列为 2017 年出版的最有价值的科技书籍之一。 私有制的时代看起来似乎结束了,在这里我将不仅仅讨论那些由我们中的许多人引入到我们的家庭与生活的设备和软件,我也将讨论...

作者: Scott Nesbitt
2018/01/08
0
0

没有更多内容

加载失败,请刷新页面

加载更多

https

进入阿里云域名后台,修改DNS为阿里云官方DNS(默认为官方),然后点击“免费开启SSL证书” 点击“申请”、“验证”并等待签发 然后根据自己的服务器类型下载对应的证书 我使用的是lnmpa工具...

临江仙卜算子
17分钟前
0
0
Quartz监听器Listerner

概述 Quartz的监听器用于当任务调度中你所关注事件发生时,能够及时获取这一事件的通知。Quartz监听器主要有JobListener、TriggerListener、SchedulerListener三种,顾名思义,分别表示任务、...

大笨象会跳舞吧
45分钟前
4
0
Call exception, tries=10, retries=35, started=38348 ms ago, cancelled=false, msg=pc-node1 row

写hbase的问题,2019-01-18 23:23:28,082 | INFO | [hconnection-0x6431d54d-shared--pool2-t5] | Call exception, tries=10, retries=35, started=38348 ms ago, cancelled=false, msg=p......

stys35
48分钟前
2
0
docker 安装portainer、gogs、redis、mongodb、es、rabbitmq、mysql、jenkins、harbor

1、准备三台虚拟机ip如下 编号 Ip 1 192.168.100.101 2 192.168.100.102 3 192.168.100.103 2、镜像应用编排 192.168.100.101 主要安装系统运维相关服务 192.168.100.102 主要安装mysql、mon...

北岩
58分钟前
8
0
storm 提交任务报SocketException错误及解决办法

提交任务爆错: org.apache.storm.thrift.transport.TTransportException: java.net.SocketException: Broken pipe (Write failed) ..... Caused by: org.apache.storm.thrift.transport.TTr......

jingshishengxu
今天
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部