如何在POST方法请求中指定SQL查询..?

时间:2016-08-17 12:26:05

标签: javascript sql http-post

如果我有以下控制器指定如何处理SQL查询:



app.controller('sqlController', ['$scope', '$http','$q', function ($scope, $http, $q) {
    $scope.executeSql = function () {
        $http.post(apiHost + '/sql/query', {sql: $scope.sql,pageNo:$scope.curPageNo}).then(function (res) {
            if(res.data.result==='error'){
                return alert(res.data.errmsg)
            }
            $scope.gridOptions.data = res.data.data;
            $scope.gridOptions.columnDefs = []
            $scope.pageSize = res.data.pageSize;
            $scope.pageNo = res.data.pageNo;
            $scope.count = res.data.count;
            var cols = res.data.data[0];
            var def = $scope.gridOptions.columnDefs;
            for(var col in cols){
                def.push({name:col, minWidth: '100'});
            }
        })
    }

    $scope.export = function(){
        var deferred = $q.defer();
        $http({
            url:apiHost+"/sql/query",
            method:'POST',
            data:{sql:$scope.sql,pageSize:99999}
        }).success(function(res){
            deferred.resolve(res.data);
        }).error(function(err){
            deferred.reject(err);
        });

        return deferred.promise;
    };

    $scope.gridOptions = {
        data: [],
        columnDefs: []
    };
}])



 HTTP post请求应该是什么样的?

有点像?:



POST /sql/query HTTP/1.1
Host: myhost.com
Proxy-Connection: keep-alive
Content-Length: 0
Accept: application/json, text/plain, */*
User-Agent: some user agent
Content-Type: application/json;charset=UTF-8
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,cs;q=0.6



 结果应该是响应中的数据库名称。 感谢您的帮助,非常感谢。

0 个答案:

没有答案