[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 658
  • Last Modified:

Jquery's $.get changes my character encoding

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
robrodp
Asked:
robrodp
  • 5
  • 3
1 Solution
 
leakim971PluritechnicianCommented:
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
 
robrodpAuthor Commented:
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
 
leakim971PluritechnicianCommented:

$.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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
robrodpAuthor Commented:
The code produces the exact same problem :(
0
 
leakim971PluritechnicianCommented:
Do you have a live link ?
0
 
robrodpAuthor Commented:
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
 
leakim971PluritechnicianCommented:
You're welcome!
0
 
leakim971PluritechnicianCommented:
Thanks for the points!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now