2

I get the following error when I attempt to make a json post request:

REXML::ParseException (The document "{\"user\":1,\"email\":\"some@email.com\"}:" does not have a valid root):

Not sure where to start.

My header looks like this:

Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:38
Content-Type:application/x-www-form-urlencoded
Cookie:_washapp_session=SOME_COOKIE_STRING
Host:myapp.herokuapp.com
Origin:http://myapp.herokuapp.com
Referer:http://myapp.herokuapp.com/user/1/add_friends
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5
X-CSRF-Token:k5bxjBJ3SCMhe1ILfChoiy6qwkYfVsg0JYZV9KDnwIg=
X-Requested-With:XMLHttpRequest
Karan
  • 14,824
  • 24
  • 91
  • 157
  • possible duplicate of [Rails throws "REXML::ParseException does not have a valid root" exception](http://stackoverflow.com/questions/6106556/rails-throws-rexmlparseexception-does-not-have-a-valid-root-exception) – Hakan Serce May 31 '12 at 21:16
  • the answers there did not help. Difference in this question is that I have given my header - which was suggested in the answer – Karan May 31 '12 at 22:57

1 Answers1

5

Content-Type should be application/json. Accept just specifies how you want the information returned, Content-Type describes what you're sending.

You can specify the data type using $.post:

$.post("http://myapp.herokuapp.com/user/1/add_friends", 
    {user:1, email:"some@email.com"},
    function(data){
        processResponse(data);
    }, 
    "json");
Jerry Clinesmith
  • 424
  • 5
  • 10