gpt4 book ai didi

javascript - Angular Js 初学者 Ajax 调用

转载 作者:行者123 更新时间:2023-11-30 12:00:37 24 4
gpt4 key购买 nike

我是 Angular js 的新手,在我的 controller.js 中是我的应用程序的 Controller ,它 100% 正常工作。我遇到的问题是如何使用 angular js 进行 ajax 调用。我正在尝试从我的服务中获取数据并使用此 ajax 将其传递到我的 index.html。当我尝试调试代码时,它只会命中 $http 但不会遍历其中的代码。我在这里做错了什么?

$http({
method: 'POST',
url: 'http://someService.site.net/site.aspx',
data:{action:'someAction', position:'founders'},
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function successCallback(response){

var json =jQuery.parseJSON(response);
var htmldata="";
for(i=0; i<json.length; i++)
{
var htmlInfo = '<li><div class=\'col\'><a href="'+ json[i].Id +'"><img width=\'100%\' height=\'auto\' src="'+json[i].Image + '" class=\'profile-img\' /><h3>' +json[i].Name+'</h3><p>'+json[i].Title+'</p></a></div></li>';

htmldata+= htmlInfo;
}
jQuery("#vflist").html(htmldata);
}, function errorCallback(response){

});

最佳答案

在成功和错误回调上标记断点。

$http 是一种服务。您在其参数中传递了所需的数据。

$http({})
^options

调用此 $http 后,它会开始工作并异步向提供的 url 发送请求。但是你不需要调试那部分。

$http({options})
.then(function(data){
// mark 1 breakpoint here
}, function(data){
// mark another breakpoint here
})

关于javascript - Angular Js 初学者 Ajax 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36708994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com