Read form data in Header in network tab - angularjs

We are using AngularJs for integrating with PaymentGateway. Success or failure URLs are redirected from PG if it is success/Failure. But in success/failure URL they are posting data about transactions. we have the code to decrypt response message. But i need the code to retrieve the particular form data in value in url encoded.
Please refer below image. i need to fetch highlighted parameter value.
Can anyone help me on this. Thanks in advance
ScreenShot

Could u please try below code.Check is that coming in console.
.success(function(data, status, headers, config) {
console.log(headers); //for success
})
.error(function(data, status, headers, config) {
console.log(headers); //for failure/error
});

Related

angularjs, $http 304 error, modify data property

we are using the Ionic framework and AngularJS to create a mobile app with phone gap build. We have a call to our api to get an array of items using $http.get, we are adding an Etag in the header if we already have data in cache.
If the data on the server has not changed we get a 304 error which is ok. We are having trouble modifying the data property on the response object form the server to our chached data in local storage.
Any help is appreciated. Thanks
return $http({
method: 'GET',
url: 'http:example.com',
params: params,
headers: customHeader
})
.success(function(data, status, headers, config) {
// do some stuff
})
.error(function(data, status, headers, config) {
if(status == '304') {
alert('this data has not changed');
data = chachedData
// change data to chached data??
}
});
HTTP 304 header code means Not modified, it's not an error. According to the RFC 2616 of HTTP 1.1, the server only sends back headers, not the response which tells the browser to use the response that it had already in cache.
It should be used to avoid heavy network traffic.
But in your case, if you want to do some cache invalidation, this is not the way (but I don't think this is what you wan't to do)
On the other hand, angular will always put 200 in status (even if it is a 304) and you shouldn't have to bother about keeping your data up to date, since you retrieve the fresher value each time (without bothering if it's from a cache in the server or fresh data from the server).

How to setup cors for angularjs to access external api?

getjson.controller('controller', function($scope, $http){
var url = "http://api.8coupons.com/v1/getsubcategory";
$http.get(url).success(function(data, status, headers, config){
$scope.jsondata = data;
console.log(data);
}).error(function(data, status, headers, config){});
});
(ed's note: added a closing brace to the outer function body.)
This code gives me the following error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.api.8coupons.com/v1/getsubcategory. This can be fixed by moving the resource to the same domain or enabling CORS.
Can somebody please tell me what is wrong and how can I fix this?
I found out an answer.
var url = "http://api.8coupons.com/v1/getcategory?callback=JSON_CALLBACK";
May be it can help someone.
If you get this kind of error change the type from get/post to jsonp
and then in url append this parameter
"?callback=JSON_CALLBACK"
without quotes

Why isn't my AngularJS post receiving data from the server?

I am posting to the server using the following in AngularJS:
$http.post('/myurl', {my: "data"}, function(data, status, headers, config) {
console.log("returned");
});
In Chrome Developer Tools, the server is sending back a 200 OK status message. However, my callback is never triggered (i.e. nothing printing to the console). Why is AngularJS not printing the message even though the server returns OK?
I've not seen request written like that, generally you want to do something like:
$http.post('/myurl', {my: "data"})
.success(function(data) {
console.log("returned");
});
or
$http.post('/myurl', {my: "data"})
.then(function(data) {
console.log("returned");
});
you can try
return $http({url: '/myurl' , method: "POST",data:my});
you can also click on F12 chrome console to see the exact error
in order to serr the results data you can add
$http({url: '/myurl' , method: "POST",data:my}).then(
function(result){
console.log(result);
}

Restservice call returns 404

I am making a http.get call in angular js which returns a json file hosted locally.
Scenario:1 -- Success
$http.get("/SuccessResponse.json").success(function(jsonDataa) {
//some code
}).error(function (data, status, headers, config) {
alert("error::"+status);
return status;
});
The above code works perfectly fine and my code inside success gets executed alright.
Scenario : 2 -- Failure
However, when I host the same json on a URI, the http.get call returns 404 and alerts "error::404".
$http.get("http://`10.23.67.43:8080/Api/util`").success(function(jsonDataa) {
//some code
}).error(function (data, status, headers, config) {
alert("error::"+status);
return status;
});
Pls note when I hit the above url on my browser, it displays the JSON perfectly alright. It is only when I try to access it through rest call, it returns 404.
Scenario : 3 -- Success
Also, if I use a public URI (e.g. http://rest-service.guides.spring.io/greeting) it again works alright.
$http.get("http://rest-service.guides.spring.io/greeting").success(..
Can someone pls help in pointing out what's the issue over here?
It's a bit difficult to distinguish how it looks when you are mixing text and markup in your codetags.
However could it be so simple that you use ` in your url?

angularjs $http.jsonp goes to .error instead of .success even when 200 is received

I'm building an AngularJS app which calls a NodeJS server that gets data from a DB.
The NodeJS returns a JSON.stringify(someArrayWithData).
Here is the AngularJS code:
$scope.getMainGroups = function(){
$http.jsonp("http://127.0.0.1:3000/get/MainGroups?callback=JSON_CALLBACK").success(function(data, status, headers, config) {
$scope.MainGroups = data;
}).error(function(data, status, headers, config) {
$scope.MainGroups = status;
});
};
$scope.MainGroups is going to the .error instead to the success even when I can see in the chrome debugger that the result came back (200 ok).
What am I missing?
You must return a valid JSON response on the server side. The 200 OK is just the GET request that is injected into the DOM. I bet you are not returning a valid JSON response from the server with right response code.
Here is an example on how to construct the response on the server side (PHP):
Simple jQuery, PHP and JSONP example?
As answered here you need to change the NodeJS response. The JSONP answer needs to start with the exact text that AngularJS added in the URL (for example 'angular.callbacks._1').
// changes in your server script used by NodeJS
// Required for JSONP calls, 'callback' matches the '?callback=JSON_CALLBACK'
app.set('jsonp callback name', 'callback');
// ... in your response change json to jsonp
res.jsonp(votes);
After doing these changes, when the server detects a 'callback' in the parameters, answers like this:
/**/ typeof angular.callbacks._1 === 'function' &&
angular.callbacks._1([{"votes":3,"title":"new topic", etc...
Now yes, AngularJS correctly calls back the 'success' function.

Resources