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 ...
分享到:
相关推荐
[Adobe.Flash.CS3以假乱真动画艺术设计].Focal.Press.How.to.Cheat.in.Flash.CS3.part2.rar
It introduces how to setup for OpenMP in Visual Studio 2005 with Inter Fortran 10.1. With a simple 'Hello world ' example
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...
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 ...
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 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"** 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
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.
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 ...
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, ...
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
Exploiting Software - How to Break Code.rar
headers: { "Accept": "application/json;odata=verbose" }, success: function(data) { var userName = data.d.Title; var email = data.d.Email; // 其他属性访问... console.log('用户名:' + userName + '...
C++ How to Program presents leading-edge computing technologies in a friendly manner appropriate for introductory college course sequences, based on the curriculum recommendations of two key ...