I'm consuming a web service via SOAP. I work on my project request and get a response expected result. the problem that I have is because I want to know when the request fails.
I want that when the request is not complete either by internet problems, timeout, etc., to be displayed a warning (console.log) stating that there is no internet or "try again." I have tried many things, but only the error is displayed by default console google chrome reporting that no internet or whatever.
the console.log() is never shown the error message console appears only google chrome console.
Not to put all my code, so basically I generate a SOAP request:
$soap.post(url,action,params).then(function(response){
//my code..
});
//.success or .error not works ..
//i need for example:
/*
.error(function(response,status,headers,config) {
console.log("problems with your connection")
});*/
documentation of soap in angular:
https://github.com/andrewmcgivery/angular-soap
sorry for my level of english.
According to the documentation (and the code), the post call returns a promise. That means you should be able to do:
$soap.post(url, action, params).then(
function(response) {
// your code
},
function(reason) {
console.log("Problems with your connection");
}
);
Promise documentation: https://docs.angularjs.org/api/ng/service/$q
Related
I have an application wherein it should work both in chrome and IE. API call using resource(ngResource) is working fine in chrome/Firefor - able to get response in success block when api is success. But in IE11 same api is going into error block. Please let me know if any configuration is required in resource factory.
So what is going on is I have integrated the PayU payment gateway in my angular app. It has a success and failure url to which it gets redirected to according to the payment response. Now those urls are client's url where the client receives the response from PayU after payment success/failure. It is sent as a POST with few query parameters that are to be parsed.
Now the problem is that since the request is a POST request on a localhost url(with the same port on which I am already running the app), the console says that 'Method is not Allowed'.
The success url is http://localhost:8005/#!/payment/success
My app is running on http://localhost:8005 (which is the same).
Now I tried to define the url in app.js so as to receive the response as follows -
.state('successScreen',{
url:'/payment/success/',
templateUrl:'partials/successScreen.html',
controller:'paySCtrl'
});
but it doesn't work.
when I am redirected to the url(http://localhost:8005/#!/payment/success) after payment, I am getting that 'Method Not Allowed' error.
The same url is working with GET request though but it cannot be a GET request as it is a response from third party so cannot change it from POST to GET.
So can anyone please help me with how can I overcome this thing or a work around maybe?
I'm trying to call an endpoint using $http.get but the call fails each time. The error status just returns -1.
How can I get a more detailed error message?
Maybe I'm making some mistake in my JavaScript but I seem to be able to call other end points fine. The request that fails for me is:
$http.get("http://www.bloomberg.com/markets/api/security/currency/cross-rates/EUR,AUD")
.success(function (data) {
alert(data);
return data;
}).error(function (status){
alert("Error status : " + status);
});
It seems that the Bloomberg API doesn't include the Access-Control-Allow-Origin header in their response. This makes it impossible for an Angular web based app to access the API since most browsers respect CORS:
If it is a CORS issue as Nasreddine suggested then you can use a CORS plugin in google chrome for testing purposes. It will get resolved when you host it in a server.
Coming to your Question a response of -1 usually indicates a timeout of request/ Server not responding.
I am writing an Outlook Add-In (for Office 365) using AngularJs (v. 1.3.15) that is using $http.get to call the SharePoint Online search API. I have abstracted my search calls into an Angular factory which I call from the primary controller.
The issue is that the $http.get call never calls the callback success or error functions. If I trace it in IE, I don't even see the request to SharePoint Online go over the wire.
Using very similar code in a stand alone Angular SPA, it works just fine. Here is some pseudo code to illustrate what I am doing...
App Controller
searchFactory.search(terms).then(function(response){
$scope.results = response.data;
},
function(error){
$scope.status = "Error";
});
Search factory:
factory.search = function(terms){
var queryStr = buildQueryStr(terms);
var results = $http.get(queryStr);
return results;
}
The factory code executes but I never see the request to the search endpoint go over the wire and neither the success nor the error function in the call in the controller is triggered.
The only error in the JavaScript console is something about no conversationId, but that doesn't seem relevant given that I'm calling the SPO API. Worth noting that the call is X-domain.
I am totally stumped. Any pointers are appreciated.
According to dev.office.com, cross-domain requests are blocked by Outlook Web due to same-origin policy:
http://dev.office.com/docs/add-ins/develop/addressing-same-origin-policy-limitations
I believe the SharePoint online API supports CORS so you can use that to get around the policy.
https://msdn.microsoft.com/en-us/office/office365/howto/create-web-apps-using-cors-to-access-files-in-office-365
I have the following in my Angular Model:
return Restangular.all('user/session/authenticate').post({user_id: user_id, password: password});
Which I call in my controller:
User.authenticate($scope.user.userId, $scope.user.username)
.then(function (authToken) {
//do stuff
};
But, it never makes a request. The headers are created, the data is there, and there is no error. I know it's probably me, but for the life of me, I can't figure out what. Also, I can successfully make GET requests to the same service.
Well, the problem wasn't me...sort of. I had the correct Restangular syntax, but a lack of understanding of how my browser works. The browser wanted me to confirm a security exception. No error was given, until I put the url directly into the url bar in FireFox.
Once I confirmed the security exception, the requests began to work.