Solved

Jquery's $.get changes my character encoding

Posted on 2010-08-30
8
644 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
  • 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
 

Author Comment

by:robrodp
ID: 33572500
The code produces the exact same problem :(
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 500 total points
ID: 33572652
You're welcome!
0
 
LVL 82

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now