It means extra < coming in your api response
Possible solutions according to me
1.Copy response in string and remove extra < and then copy it to original form and then do parsing
Or
2.Tell your backend/api developers to remove it from response or db.
but in response in postman it shows correct json then why its not coming in app
Yes gone through your link.
I think in response format of your server it mentioned xml as response type can you please confirm.
Also for headers try to use this
import { HttpHeaders } from '@angular/common/http';
const httpOptions = {
headers: new HttpHeaders({
'Content-type': 'application/json',
})
};
still not working it gives response in html code and in server side he also mentioned type as application/json
When you are requesting login api try to check response.
1.If you are testing on Android Device/Emulator
do it in Google Crome by inspect
1.what is response type?
2.what is response:?
2 .if you are testing it on ios Simulator/Device
try to check on Safari browser in develop option so that you can get details.
If possible try to paste your response which you are getting on login api.
Try to use https://codebeautify.org/ to check whether response in correctly formated or not.
when i print response in console using console.log(âjson dataâ,res) it gives
json data
Response {_body: ââ”â” â” <meta charset=âŠype=âtext/javascriptâ>â” â”â, status: 200, ok: true, statusText: âOKâ, headers: Headers, âŠ}
headers: Headers
_headers: Map(4) {âpragmaâ => Array(1), âcontent-typeâ => Array(1), âcache-controlâ => Array(1), âexpiresâ => Array(1)}
_normalizedNames: Map(4) {âpragmaâ => âpragmaâ, âcontent-typeâ => âcontent-typeâ, âcache-controlâ => âcache-controlâ, âexpiresâ => âexpiresâ}
proto: Object
ok: true
status: 200
statusText: âOKâ
type: 2
_body: ââ”â” â” â” Quality Control | Admin System Log inâ” â” â” â” â”â” â” â” â” â” â”
Admin Systemâ”
Sign In
â”â” â”
proto: Body
From your response It looks like its not proper JSON response format.
To print response in JSON write like this
console.log(âjson dataâ, JSON.stringify(res))
It will print JSON format of your response.
Please paste your code on https://codebeautify.org/ and check whether JSON is valid or not
and paste that json here.
You are testing app on iOS device/Simultor or Android device/Emulator ?
Note:While pasting code on forum try not to reveal urls
when i use console.log(âjson dataâ, JSON.stringify(res)) this it prints html code in json format
and iâm testing app on android device and google chrome
json comes like this:
{"_body":"\n\n \n <meta charset=âUTF-8â>\n Quality Control | Admin System Log in\n \n <link href=âhttp://146.66.92.93/~advent37/QualityControl/assets/bootstrap/css/bootstrap.min.cssâ rel=âstylesheetâ type=âtext/cssâ />\n <link href=âhttps://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.cssâ rel=âstylesheetâ type=âtext/cssâ />\n <link href=âhttp://146.66.92.93/~advent37/QualityControl/assets/dist/css/AdminLTE.min.cssâ rel=âstylesheetâ type=âtext/cssâ />\n\n \n \n \n \n <body class=âlogin-pageâ>\n <div class=âlogin-boxâ>\n <div class=âlogin-logoâ>\n <a href="#">\n\t\t<img src=âhttp://146.66.92.93/~advent37/QualityControl/assets/images/logo_new.pngâ class=âuser-imageâ alt=âUser Imageâ/>\n\t\t
Admin System\n \n <div class=âlogin-box-bodyâ>\n <p class=âlogin-box-msgâ>Sign In
\n \n \n \n\n \n",âstatusâ:200,âokâ:true,âstatusTextâ:âOKâ,âheadersâ:{âpragmaâ:[âno-cacheâ],âcontent-typeâ:[âapplication/json; charset=UTF-8â],âcache-controlâ:[âno-storeâ," no-cache"," must-revalidate"],âexpiresâ:[âThuâ," 19 Nov 1981 08:52:00 GMT"]},âtypeâ:2}
Yes thats what I want.
Its problem from your sever side response
1.Why html is coming in response? Is that architecture of your app/project that HTML will come in response and then you will render it on screen?
2.If answer of above question is NO . Then tell your backend team to give proper JSON format response
Its like response in JSON but internally HTML putted in in objects.
So final solution can be response should be proper JSON.
See at the time postman can be showing response correctly but in coding its not that much easy to parse this type of response.
Hi
Have you resolved that?
If so please let me know how.
Thanks
Not yet still iâm facing same issue and backend developer says all is correct from his side
and when i use static json like below
this.resposeData = {
âemailâ: "admin@example.com",
âpasswordâ: âadminâ,
âstatusâ: 1
}
console.log(âdataâ, this.resposeData);
console.log(âuserdataâ, this.resposeData.userData );
if (this.resposeData.userData ) {
localStorage.setItem(âuserDataâ, JSON.stringify(this.resposeData ))
this.navCtrl.push(HomePage);
}
else {
this.presentToast(âPlease enter valid username and passwordâ);
}
then console.log(âuserdataâ, this.resposeData.userData ); it prints undefined
The server may be doing a redirect
The content of the html suggests some sort of login page
Go to the link with ur browser and login
If it then provides Json data, u know u have an authentication step to complete prior to fetching data (in header etc)
console.log(âuserdataâ, this.resposeData.userData ); it prints undefined
if userData is not in resposeData then it will not print.
actually, the problem is that iâm sending parameters in json format and in server side it takes response in form data type
and thanks for your help