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.Get.Control.of.Your.Time.and.Your.Life.2006.Scan.CHS-INTERNET.pdf
their methods in order to fully understand how they work and what they are capable of. By the end of the book, you'll be an expert in its implementation. We already have a basic working knowledge of ...
Do you want to get started with Internet of Things… This book is all about getting started with Internet of Things using Nodemcu, it’s a development kit made out of ESP8266, which is a cheap Wi-Fi ...
How Not to Program in C++.pdf
A really good web development framework... You'll learn how jQuery interacts with other tools and frameworks and how to build jQuery plugins. This book requires a modest knowledge of JavaScript and Ajax.
It introduces how to setup for OpenMP in Visual Studio 2005 with Inter Fortran 10.1. With a simple 'Hello world ' example
Prentice.Hall.Java.How.to.Program.9th.Edition
It is important to know how to extend the power of jQuery with custom methods as it is a fundamental skill for a top jQuery developer. Chapter 13 introduces the jQuery Deferred Object, which was ...
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-...
There just isn’t the space in a book about jQuery to cover HTML in its entirety. If you want a complete reference for HTML and CSS, then I suggest another of my books: The Definitive Guide to HTML5,...
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 ...
Java How to Program (Late Objects), Tenth Edition is intended for use in the Java programming course. It also serves as a useful reference and self-study tutorial to Java programming. The Deitels’ ...
If you want to learn how to program, working with Python is an excellent way to start. This hands-on guide takes you through the language a step at a time, beginning with basic programming concepts ...
How to Use Buses in Simulink.zip
Unit_3_How_do_you_get_to_school课件.ppt
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, ...
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.