如何在.getJSON JQuery的集编码 [英] How to set encoding in .getJSON JQuery

查看:111
本文介绍了如何在.getJSON JQuery的集编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的web应用程序,我提交了一些与jQuery $表单域。的getJSON()方法。我有一些问题的编码。该字符集我的应用程序是的charset = ISO-8859-1 ,但我认为这些字段提交的 UTF-8

In my web app, I submit some form fields with jQuery $.getJSON() Method. I am having some problems with the encoding. The character-set of my app is charset=ISO-8859-1 but I think these fields are submitted with UTF-8.

有谁知道,我怎么可以设置在 $。的getJSON 通话编码?

Does anyone know, how I can set encoding in $.getJSON calls?

推荐答案

我想你可能不得不使用的 $。阿贾克斯() 如果要更改编码,请参阅的contentType 参数如下(在成功错误回调假设你有< D​​IV ID =成功> < / DIV> < D​​IV ID =错误>< / DIV> 在html):

I think that you'll probably have to use $.ajax() if you want to change the encoding, see the contentType param below (the success and error callbacks assume you have <div id="success"></div> and <div id="error"></div> in the html):

$.ajax({
    type: "POST",
    url: "SomePage.aspx/GetSomeObjects",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: "{id: '" + someId + "'}",
    success: function(json) {
        $("#success").html("json.length=" + json.length);
        itemAddCallback(json);
    },
    error: function (xhr, textStatus, errorThrown) {
        $("#error").html(xhr.responseText);
    }
});

其实我只是不得不前做一个小时左右,真巧!

I actually just had to do this about an hour ago, what a coincidence!

这篇关于如何在.getJSON JQuery的集编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆