Nulra
August 17, 2017, 9:50am
1
Hi, I am using POST to call api with a java server and following the below link to update the web.xml in backend server to solve CORD problem:
java, ajax, struts2
but when I call the api again, it is not return a json result i wanted. It return :
Response {_body: “”, status: 200, ok: true, statusText: “OK”, headers: Headers, …} .
Did anyone know how to deal with it? Thanks a lot =)
you didn’t want a status 200?
Nulra
August 17, 2017, 9:58am
3
Hi, FnnHuman, thanks for your reply. Because I have data returned by server in this api, i want those data rather than status 200.
but status 200 means that everything is good and if there was any data returned from server you should have access to it now
this.http.post('something/api/', JSON.stringify(details), { headers: headers })
.map(res => res.json())
.subscribe(data => {
console.log(data); //you have access to data
}, (err) => {
console.log(err); //oops error
});
How are you calling that address?
What code is outputting that Reponse object you posted?
Did you look at the request in your browser’s dev tools network tab? Does it return the data?
Nulra
August 17, 2017, 1:44pm
6
I call it this way:
this.http.post(apiUrl+'register', JSON.stringify(body), {headers: headers})
.map(res => res.text() ? res.json() : res)
.subscribe((data) => {
console.log("NULRA CHECKING : ", data);
},(err) => {
reject(err);
});
But the data i printed is status 200… not the data that I needed
Why this? See the example @FnnHuman posted.
Nulra
August 17, 2017, 5:38pm
8
I have try @FnnHuman example, it will go to error directly.