【问题标题】:$http(). Get a SyntaxError when passing an extra GET parameter with "?"$http()。使用“?”传递额外的 GET 参数时获取 SyntaxError
【发布时间】:2012-07-31 14:58:10
【问题描述】:

我按照文档示例实现了一个 fetch 方法。 就我将?format=json 添加到$scope.url 而言,它运行良好。

    $scope.method = 'GET';
    $scope.url = "/activite/273/usagers?format=json";

    $scope.fetch = function($event) {

        $scope.code = null;
        $scope.response = null;

        $http({method: $scope.method, url: $scope.url, cache: $templateCache}).
          success(function(data, status) {
            $scope.status = status;
            $scope.users = data;
            $scope.search.status = $scope.userStatus;
            $('#UserList').modal('show');
          }).
          error(function(data, status) {
            $scope.response = data || "Request failed";
            $scope.status = status;
            $scope.userStatus = '';
        });
        $event.preventDefault();
    };

有什么想法吗?

【问题讨论】:

    标签: javascript http angularjs


    【解决方案1】:

    根据API documentation,看起来您应该以任何方式在单独的params 对象中传递参数。所以:

    $scope.method = 'GET';
    $scope.url = "/activite/273/usagers";
    $scope.params = {
        format: 'json
    };
    

    【讨论】:

    • 这似乎不是强制性的。我设法让它在没有它的情况下工作。还是谢谢
    • 不是史诗般的错误修复,请参阅我的回答。无论如何感谢您的投入,我一定会使用它。
    【解决方案2】:

    其实是json格式本身的问题,把"全部换成了&quote;。我解决了这个问题。

    【讨论】:

    • 并不难,但我一开始在浏览器中看不到它。我通过网络检查器注意到了它。
    猜你喜欢
    • 2018-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-24
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 2018-01-15
    相关资源
    最近更新 更多