0

I have a question related to $http post service in Angular JS. I am currently working on CMS (Content Management System) project, where I need to send HTML data to rest api. Currently, I am constructing payload object in angularjs controller, but when I post html data I get unable to decode value in developer console. Because of this post request is not happening.
This is happening because escape character present in data.

For example:

var payloadData = {
    "name":"Test Document",
    "desc":"test 123",
    "content":"<div style="color:red;text-align:center;">%%header%%</div>"
}

Developer console screenshot

2
  • Can you show the code for your controller and http request? You should be doing something similar to what is found here:docs.angularjs.org/api/ng/service/$http#post Commented Apr 6, 2016 at 4:39
  • var payloadData = {"content_category_id":category_id+'',"content":$scope.froalaOptions.froalaEditor('html.get'),"description":description,"name":name}; customHttpService.updateData(url,JSON.stringify(payloadData),helperService.postReqHeader()) .then(function(result){ // success //Content Successfully Updated ! }, function(err){ // error //Error Occured While Updating The Content ! }); Commented Apr 6, 2016 at 4:52

3 Answers 3

1

use $http.post('url here',JSON.stringify(payloadData));

Sign up to request clarification or add additional context in comments.

3 Comments

var payloadData = {"content_category_id":category_id+'',"content":$scope.froalaOptions.froalaEditor('html.get'),"description":description,"name":name}; customHttpService.updateData(url,JSON.stringify(payloadData),helperService.postReqHeader()) .then(function(result){ // success //Content Successfully Updated ! }, function(err){ // error //Error Occured While Updating The Content ! });
Hello after using JSON.stringify(payload) , still not able to use post or put http methods.
use the variable and for ex: postData = {your Payload} and pass postData to posta api
0

how about using $http.post(url,payloadData,headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'})

Let us know if it works or not

2 Comments

if you see my code snippet i am using helperService.postR‌​eqHeader() which give me headers: { 'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8", 'Authorization': 'Bearer '+$cookies.authAppToken }
One interesting thing happening in this case. I am not aware of this, but if i remove header:{'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'} with this, "post request is successful". Can anybody let me know , why this is happening ?
0

One interesting thing happening in this case. I am not aware of this, but if i remove header:{'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'} with this, "Post request is successful".

Can anybody let me know , why this is happening ? This will helpful in understanding the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.