是否有angularJS的方法那等于的getJSON。 [新手警报] [英] Is there a method in angularJS thats equal to getJSON. [Newbie alert]
问题描述
我在JavaScript中,angularJS和JQuery新手,但我刚开始编程angularJS应用,在那里我使用jQuery从这样的网络服务器得到JSON:
I'm newbie at javascript, angularJS and JQuery, but I have just started programming a angularJS app where i use JQuery to get a JSON from a webserver like this:
var obj = $.getJSON( "http://something.com/lol?query="+ $scope.searchString, function() {
$scope.items = obj.responseJSON.entries;
}
有没有一种方法,等于$ .getJSON在angularJS?所以,我没有导入jQuery库。
Is there a method equal to $.getJSON in angularJS? So that I don't have to import the JQuery library.
在此先感谢,新手。
这是我的解决方案迄今:
This is my solution so far:
function InstantSearchController($scope, $http){
$scope.search = function() {
$http.jsonp("http://something.com/lol?query="+ $scope.searchString + "?json_callback=JSON_CALLBACK").success(
function(data, status) {
console.log(data);
}
);
}
但我得到的错误信息:
but I'm getting the error msg:
未捕获的SyntaxError:意外的标记:
Uncaught SyntaxError: Unexpected token :
这是为什么?我究竟做错了什么?
}
why is this? what am I doing wrong? }
推荐答案
由于的帮助下,我从人民得到了回答我的问题,我终于设法解决它,我做了这样的:
Because of the help i got from people answering my question I finally managed to fix it, and i did it like this:
app.controller('myController', function($scope, $http){
$scope.items = [];
$scope.search = function() {
$http({method: 'JSONP', url: "http://something.com/lol?callback=JSON_CALLBACK&query="+ $scope.searchString}).
success(function(data, status) {
$scope.items = data.entries;
}).
error(function(data, status) {
console.log(data || "Request failed");
});
};
希望这有助于人谁在未来有同样的问题:D
Hope this helps anyone who has the same problem in the future :D
这篇关于是否有angularJS的方法那等于的getJSON。 [新手警报]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!