AJAX: intriguing problem passing special character...

AJAX: intriguing problem passing special character...


I did solve the problem, but I found it so intriguing I wanted some opinions:

I send a string to server with AJAX in classic way:
  1. queryStr = "?namePicked=" + names[0];
  2.        
  3. $.ajax({ url:"string.jsp" + queryStr,
  4.     type:"POST",
  5.     success:function(data){
  6.         $("#outputString").html( data );
  7.     },
  8.     error: function() {
  9.          $("#outputString").html("fail");
  10.     }
  11. });
  12.        
       
sometimes that name will include a special character, for example René

this special char gets lost along the AJAX route... when print back in front end it prints: 'Ren'

however, if I send the string thus:

  1. $.ajax({ url:"string.jsp",
  2.     type:"POST",
  3.     data:{namePicked:names[0]},
  4.     success:function(data){
  5.         $("#outputString").html( data );
  6.     },
  7.     error: function() {
  8.          $("#outputString").html("fail");
  9.     }
  10. });
   
no problem with spec char........ ????


way I discovered this is that I also send a whole array, thus:

  1. if (names.length > 0 ) {
  2.     $.ajax({ url:"array.jsp",
  3.         type:"POST",
  4.         data: {names:names},
  5.         success:function(data){
  6.             $("#outputArray").html( data );
  7.         },
  8.         error: function() {
  9.              $("#outputArray").html("fail");
  10.         }
  11.     });
  12. } else {
  13.     $("#outputArray").html("done -- no more names in list");   
  14. }
       
also no problem with special character(s)......       

curiouser and curiouser...;-)  was wondering if anyone has a comment...

(interesting discovery was that there is a way to send a single string to server with AJAX without a using query string.. this is new to me... I guess if you need to send more than one string you do need to go the query string route.. unless you send them one-by-one (or something like that...;-)

thank you....