如何在 angularjs 控制器中获取 json 数据
How do I fetch json data in angularjs controller
https://jsonplaceholder.typicode.com/posts 我必须从此 link 获取数据并将其显示在我的浏览器中。在 Javascript 中,我曾经使用 XMLHttpRequest 来完成它,然后使用 JSON.parse(response) 来解析它。有什么方法可以在 angularjs 中实现类似的效果吗?谢谢
您可以查看此内容link angular http get
样本
$http({
method: 'GET',
url: '/someUrl'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
/ / called asynchronously if an error occurs
// or server returns response with an error status.
});
https://jsonplaceholder.typicode.com/posts 我必须从此 link 获取数据并将其显示在我的浏览器中。在 Javascript 中,我曾经使用 XMLHttpRequest 来完成它,然后使用 JSON.parse(response) 来解析它。有什么方法可以在 angularjs 中实现类似的效果吗?谢谢
您可以查看此内容link angular http get
样本
$http({
method: 'GET',
url: '/someUrl'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
/ / called asynchronously if an error occurs
// or server returns response with an error status.
});