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:
- queryStr = "?namePicked=" + names[0];
-
- $.ajax({ url:"string.jsp" + queryStr,
- type:"POST",
- success:function(data){
- $("#outputString").html( data );
- },
- error: function() {
- $("#outputString").html("fail");
- }
- });
-
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:
- $.ajax({ url:"string.jsp",
- type:"POST",
- data:{namePicked:names[0]},
- success:function(data){
- $("#outputString").html( data );
- },
- error: function() {
- $("#outputString").html("fail");
- }
- });
no problem with spec char........ ????
way I discovered this is that I also send a whole array, thus:
- if (names.length > 0 ) {
- $.ajax({ url:"array.jsp",
- type:"POST",
- data: {names:names},
- success:function(data){
- $("#outputArray").html( data );
- },
- error: function() {
- $("#outputArray").html("fail");
- }
- });
- } else {
- $("#outputArray").html("done -- no more names in list");
- }
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....