Tag: angular http

通过GET请求通过AngularJS的$ http服务发送数组

我需要使用$http服务发送GET请求。 其中一个参数将是一个ID数组。 该url看起来像这样一个mysite.com/items?id[]=1&id[]=2&id[]=3&id[]=4 我试过这种方法 $http( method: 'GET', url: '/items', params: { id: ids // ids is [1, 2, 3, 4] } ) 但我obain的url是mysite.com/items?id=%5B%221%22%2C%222%22%2C%223%22%2C%224%22%5D 这是因为Angular正在将我的值转换为JSONstring。 有没有办法得到我想要的行为? [更新] 我解决了这个问题,感谢Jonathan的build议,使用jQuery的$.param() 。 $http( method: 'GET' url: '/items?' + $.param({id: ids}) )

Angularjs从$ http自动完成

我试图写一个自动完成指令,使用$ http请求从服务器获取数据(不使用任何外部插件或脚本) 。 目前它只适用于静态数据。 现在,我知道我需要将我的$ http请求插入到指令的source:中,但是我找不到任何关于这个主题的好文档。 http请求 $http.post($scope.url, { "command": "list category() names"}). success(function(data, status) { $scope.status = status; $scope.names = data; }) . error(function(data, status) { $scope.data = data || "Request failed"; $scope.status = status; }); 指示 app.directive('autoComplete', function($timeout) { return function(scope, iElement, iAttrs) { iElement.autocomplete({ source: scope[iAttrs.uiItems], select: function() { $timeout(function() { iElement.trigger('input'); […]

在AngularJS http处理错误然后构造

在使用AngularJS“http get then”构造(承诺)时,如何处理HTTP错误,例如500? $http.get(url).then( function(response) { console.log('get',response) } ) 问题是,对于任何非HTTP响应,不调用内部函数。

$ http get参数不起作用

有谁知道为什么这不起作用? $http .get('accept.php', { source: link, category_id: category }) .success(function (data, status) { $scope.info_show = data }); 这工作: $http .get('accept.php?source=' + link + '&category_id=' + category) .success(function (data, status) { $scope.info_show = data });

AngularJs ReferenceError:$ http没有定义

我有以下的Angular函数: $scope.updateStatus = function(user) { $http({ url: user.update_path, method: "POST", data: {user_id: user.id, draft: true} }); }; 但是,每当这个函数被调用,我得到ReferenceError: $http is not defined在我的控制台中ReferenceError: $http is not defined 。 有人能帮我理解我在这里做错了吗?

从jquery $ .ajax到angular $ http

我有这个jQuery代码工作很好交叉来源: jQuery.ajax({ url: "http://example.appspot.com/rest/app", type: "POST", data: JSON.stringify({"foo":"bar"}), dataType: "json", contentType: "application/json; charset=utf-8", success: function (response) { console.log("success"); }, error: function (response) { console.log("failed"); } }); 现在我打算把这个转换成Angular.js代码没有任何成功: $http({ url: "http://example.appspot.com/rest/app", dataType: "json", method: "POST", data: JSON.stringify({"foo":"bar"}), headers: { "Content-Type": "application/json; charset=utf-8" } }).success(function(response){ $scope.response = response; }).error(function(error){ $scope.error = error; }); 任何帮助赞赏。

如何在成功处理程序外使用$ http promise response

$scope.tempObject = {}; $http({ method: 'GET', url: '/myRestUrl' }).then(function successCallback(response) { $scope.tempObject = response console.log("Temp Object in successCallback ", $scope.tempObject); }, function errorCallback(response) { }); console.log("Temp Object outside $http ", $scope.tempObject); 我在successCallback得到响应,但没有获得$scope.tempObject外的$http $scope.tempObject 。 其显示undefined 。 如何在$http之后访问response或$scope.tempObject

处理服务中的$ http响应

我最近发布了关于我在SO所面临的问题的详细描述。 因为我无法发送实际的$http请求,所以我使用timeout来模拟asynchronous行为。 从@Gloopy的帮助下,从我的模型查看数据的function是正确的 现在,当我使用$http而不是$timeout (本地testing)时,我可以看到asynchronous请求成功, data在我的服务中填充了json响应。 但是,我的观点并没有更新。 在这里更新了Plunkr

如何将数据作为表单数据而不是请求有效载荷发布?

在下面的代码中,AngularJS $http方法调用URL,并将xsrf对象作为“Request Payload”提交(如Chromedebugging器networking选项卡中所述)。 jQuery $.ajax方法执行相同的调用,但将xsrf作为“表单数据”提交。 我如何使AngularJS提交xsrf作为表单数据而不是请求有效载荷? var url = 'http://somewhere.com/'; var xsrf = {fkey: 'xsrf key'}; $http({ method: 'POST', url: url, data: xsrf }).success(function () {}); $.ajax({ type: 'POST', url: url, data: xsrf, dataType: 'json', success: function() {} });