?
Solved

Jquery's $.get changes my character encoding

Posted on 2010-08-30
8
Medium Priority
?
653 Views
Last Modified: 2012-05-10
I am using $.get to send some variables to an asp file that saves them to an sql table. When I use a regular form in a separate window special characters (áéíóúñ) are saved correctly but when I use ajax to do so the encoding used is UTF-8 which saves some weird characters instead of the special characters. Any ideas? I need ISO-8859-1!

0
Comment
Question by:robrodp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 33563599
Use $.ajax and beforeSend(XMLHttpRequest) :

http://api.jquery.com/jQuery.ajax/
$.ajax({
  url: url,
  data: data,
  success: success,
  dataType: dataType,
  beforeSend: function(req) {
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1");
  }
});

Open in new window

0
 

Author Comment

by:robrodp
ID: 33563813
Sorry, but I'm new to jquery, how would you write this $.get in terms of a $.ajax?
$.get("submit.asp", { var1: 'var1', var2: 'var2' },
function(data){
function1(data);
function2(data);
function3(data);
...
functionN(data);
});

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 33563834

$.ajax({
  url: "submit.asp",
  data: { var1: 'var1', var2: 'var2' },
  success: function(data){
              function1(data);
              function2(data);
              function3(data);
              ...
              functionN(data);
  },
  beforeSend: function(req) {
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1");
  }
});

Open in new window

0
Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

 

Author Comment

by:robrodp
ID: 33572500
The code produces the exact same problem :(
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33572566
Do you have a live link ?
0
 

Author Comment

by:robrodp
ID: 33572622
It's being programmed in the intranet so, sorry no. But I have solved it using htmlEncode, a function that encodes on the client side (Javascript: http://www.tumuski.com/code/htmlencode/) and decodes on the server side (ASP: http://www.psacake.com/web/func/htmldecode_function.htm). Seems to work fine with the original $.get and the $.ajax sequence

Thanks for the support!!
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 33572652
You're welcome!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33572668
Thanks for the points!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question