I used this.http.get method in ionic v2…but don’t know how to use http.post in ionic v2
my code for http.get is
this.http.get('My URL')
.subscribe(data => {
//this.cat = JSON.stringify(data);
this.d = data.json().Data;
console.log("Success");
},
err => {
alert("Error : " + err);
});
So I want to learn how to use post in this…I done this in post method like below :
this.http.post('My URL', data).subscribe(data => {
debugger;
alert("Data Added");
});
And what happens? What do you expect to happen? How are those two things different?
this.http.post('My URL', data).subscribe(data => {
debugger;
alert("Data Added");
});
this is not working and I have to call API using this method…I can’t use map for post method…I want to insert data in database like below code means without map
this.http.get('My URL')
.subscribe(data => {
//this.cat = JSON.stringify(data);
this.d = data.json().Data;
console.log("Success");
},
err => {
alert("Error : " + err);
});
So I want syntax for post method
If you have read many of my posts here, you understand how much I despise the phrase “not working”. I asked very specific questions, you answered none of them.
getting error
'Response with status : 500 Internal Server error for MyURL
Does your API allow POST calls?
I’m working on it…call you after solve it
soomit
August 16, 2017, 8:02am
10
Same code I am using working fine.
Yes it is…But when I’m trying with get method then it is working fine but every time it is not solution…So I have to do using post method
please send me value format of postParams variable
let postParams = {
"name": this.name,
"email": this.email,
"phone": this.phone,
"password": this.password,
"photos":this.photos
}
okk.thanks
How can I extract data from response of post
this.http.post('url', details)
.subscribe(data => {
alert(data.text() );
console.log("Success");
},
err => {
alert("Error : " + err);
});
}
If I do data.text() then I got json but I have to get a param from that json array but I don’t know how to do it
reponse is like this
{"MESSAGE":"Successfully !","ORIGINAL_ERROR":"","ERROR_STATUS":false,"RECORDS":false}
I want only MESSAGE from this
I got this as response
{"MESSAGE":"Successfully !","ORIGINAL_ERROR":"","ERROR_STATUS":false,"RECORDS":false}
It is 100% right…
but I want to get only value of MESSAGE…but how can I do it…That I have to know
.subscribe(data => {
this.data = data.json();
let response = this.data.MESSAGE;
alert(response);
}, error => {
//console.log(error);// Error getting the data
alert("No Internet connection!")
});
its should be work fine.
It is not working…No error is occurring
@shivani8710 But the code is working for me.please show me you code.
data:any;
this.http.post('URL', details)
.subscribe(data => {
debugger;
this.data = data.json();
let response = this.data.MESSAGE;
alert(response);
debugger;
console.log("Success");
},
err => {
alert("Error : " + err);
});