【问题标题】:REXML::ParseException does not have a valid rootREXML::ParseException 没有有效的根
【发布时间】:2012-05-31 21:08:51
【问题描述】:

我尝试发出 json post 请求时收到以下错误:

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

不知道从哪里开始。

我的标题是这样的:

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

【问题讨论】:

标签: ruby-on-rails ajax json post rexml


【解决方案1】:

Content-Type 应该是application/jsonAccept 只是指定您希望如何返回信息,Content-Type 描述您发送的内容。

您可以使用$.post指定数据类型:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多