weixin_33694172 2015-12-13 21:36 采纳率: 0%
浏览 35

IE上的Web API编码错误

Why I get this symbol � instead of ąčęėįš. I pass parameter via Ajax. On chrome works fine, but on IE its not working.

Ajax:

var comment = document.getElementById("commentstext").value;
$.ajax({
    type: "get",
    dataType: "json",
    contentType: 'charset=utf-8',
    url: url,
    data: "state=false&comment=" + comment
});

api:

[DnnAuthorize()]
[HttpGet]
[ActionName("insert")]

public void InsertRecord(bool state, string comment)
{
       ...
}

url: http://.../API/Rate/insert?state=false&comment=ąčęąčę

IE version: 11 and 9

Chrome version: 33 and 46

Now I cann't test other browser

Its work after i add this: comment = encodeURIComponent(comment);

  • 写回答

1条回答 默认 最新

  • weixin_33739646 2015-12-14 20:15
    关注

    How about this:

    var comment = document.getElementById("commentstext").value;
    $.ajax({
        type: "get",
        dataType: "json",
        url: url,
        data: { 
            state: false,
            comment: comment
        }
    );
    

    And also specifying UTF encoding in your web.config:

    <system.web>
        <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
        ...
    </system.web>
    
    评论

报告相同问题?