`
leonzhx
  • 浏览: 786876 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

How to set encoding in .getJSON JQuery

    博客分类:
  • Web
阅读更多

Q:

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 this fields are submitted with UTF-8.

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

 

 

A:

 

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);
    }
});
 

If you want to use $.getJSON() you can add the following before the call :

$.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=utf-8"});
 

You can use the charset you want instead of utf-8.

 

 

contentType : When sending data to the server, use this content-type. Default is "application/x-www-form-urlencoded", which is fine for most cases.

scriptCharset : Only for requests with 'jsonp' or 'script' dataType and GET type. Forces the request to be interpreted as a certain charset. Only needed for charset differences between the remote and local content.

You may need one or both ...

 

 

分享到:
评论

相关推荐

    how to set for OpenMP in Visual Studio 2005

    It introduces how to setup for OpenMP in Visual Studio 2005 with Inter Fortran 10.1. With a simple 'Hello world ' example

    Preproduction.Blueprint.How.to.Plan.Game.Environments.and.Level.Designs.2nd.Ed

    This could be for a playable level or a game environment exploration to show off in a portfolio. Planning process is called pre-production and what you end up with is a "Preproduction Blueprint". It...

    How.to.Use.IBM.SPSS.Statistics.epub

    Each section describes how to interpret results and express them in a research report after the data are analyzed. For example, students are shown how to phrase the results of a significant and an ...

    Pro.jQuery.2.0

    In Pro jQuery 2.0 seasoned author, Adam Freeman, demonstrates how to get the most from jQuery 2.0 by focussing on the practical features of the technology and how they can be applied to solving real-...

    Beginning.JSON.1484202031

    Beginning JSON is the definitive guide to JSON - JavaScript Object Notation - today’s standard in data formatting for the web. The book starts with the basics, and walks you through all aspects of ...

    JQuery In Action.PDF

    **"JQuery in Action"** is a valuable resource for both beginners and experienced developers looking to enhance their web development skills. By following the structured approach outlined in the book, ...

    Unit_3_How_do_you_get_to_school课件.ppt

    Unit_3_How_do_you_get_to_school课件.ppt

    Packt.Learning.Jquery3

    We start by configuring and customising the jQuery environment, and getting hands-on with DOM manipulation.... Also, we’ll learn how to integrate jQuery with your favourite back-end framework.

    jQuery.in.Action.3rd.Edition.161729207

    In it, you'll learn how to traverse the DOM, handle events, perform animations, write jQuery plugins, perform Ajax requests, and even unit test your code. Its unique Lab Pages anchor each concept in ...

    SQL.and.Relational.Theory.How.to.Write.Accurate.SQL.Code.3rd.Edition

    In this book, Chris Date explains relational theory in depth, and demonstrates through numerous examples and exercises how you can apply it to your use of SQL. This third edition has been revised, ...

    JavaScript.JSON.Cookbook.1785286900

    Then, you'll learn how to use JSON in simple AJAX applications using AngularJS and jQuery. Next, you will learn how to exchange objects with databases using MongoDB and CouchDB. You'll also explore ...

    How to Get Ideas - Jack Foster.pdf

    How to Get Ideas - Jack Foster.pdf

    Exploiting Software - How to Break Code.rar

    Exploiting Software - How to Break Code.rar

    How to get current user of sharepoint 2013

    headers: { "Accept": "application/json;odata=verbose" }, success: function(data) { var userName = data.d.Title; var email = data.d.Email; // 其他属性访问... console.log('用户名:' + userName + '...

    RK3399的DRM-HOWTO测试

    RK3399的DRM-HOWTO测试 最近在学习与调试RK3399的DRM显示架构,网上有很多例程,其中介绍比较多的是来于David Herrmann’s Github的drm-howto.开源代码 但这些源码下载后执行make编译出来的执行文件只能在PC机上测试...

Global site tag (gtag.js) - Google Analytics