Javascript http.get请求跳过函数(结果)
我试图找出为什么我的函数在请求完成后会跳转。。 我的意思是它没有进入Javascript http.get请求跳过函数(结果),javascript,angularjs,Javascript,Angularjs,我试图找出为什么我的函数在请求完成后会跳转。。 我的意思是它没有进入。然后(函数(结果){} 我认为这可能是因为元素具有onclick属性和href属性 你见过这个问题吗 var app = angular.module('devicesFromGroup', ['ngResource']); var myInjector = angular.injector(["ng"]); var $http = myInjector.get("$http"); //var $scope= myInjec
。然后(函数(结果){}
我认为这可能是因为
元素具有onclick
属性和href
属性
你见过这个问题吗
var app = angular.module('devicesFromGroup', ['ngResource']);
var myInjector = angular.injector(["ng"]);
var $http = myInjector.get("$http");
//var $scope= myInjector.get("$scope");
function funcb($http){
console.log("OLIEIEIEIEI");
$http.get('http://localhost:8080/api/stuff/2')
.then(function(result) {
console.log("it's not printed");
});
}
function funcC(id){
myInjector.invoke(funcb);
return true;
};
然后,在其他JavaScript中,我有:
var a = document.createElement("a");
a.setAttribute('href',"http://localhost:8080/DevicesFromGroup.html");
a.setAttribute('onclick',"funcC(id);");
调用可能返回错误。然后调用块只是为了成功。请参阅下文,我添加了一个catch块,用于在控制台中显示错误
function funcb($http){
console.log("OLIEIEIEIEI");
$http.get('http://localhost:8080/api/stuff/2')
.then(function(result) {
console.log("it's not printed");
})
.catch(function (err) {
console.log("There was an error: "+err);
});
}
您如何调用它?您提到href,如果您使用的是锚定标记,您可能需要阻止链接的默认操作您是否尝试添加错误回调?我假设您的Web服务不返回HTTP 200,因此您的成功回调永远不会被调用。请检查:我的目标是单击一个元素并在新的h上执行该函数tml(我提到了href)…是的,我认为你是对的sterling archer..我如何解决它?Web服务返回http200FYI:tag代表angular 2+,tag代表angular 1.x@PJMC@PJMC另外,请注意,放置错误的标签只会使愿意帮助的人更难完成任务。谢谢。但事实并非如此。它返回http 200