Topic
2 replies Latest Post - ‏2011-02-05T01:40:57Z by KGopiNarasimha
muba
muba
1 Post
ACCEPTED ANSWER

Pinned topic Ajax calling not encoding in utf-8(ie) problem

‏2010-09-06T04:11:35Z |
Hi,

Using arabic characters,

I have a project, in the admin panel, where i am trying to change the value in the text box(ajax) on onblur js function.
Firefox simply working great but i am getting square brackets in the text box in the browser ie.

I simply guessing the value from the text box is not in the form of utf-8 encoding, i am calling the external javascript file, this is the code am using..

// JavaScript Document

var xmlhttp;
//function namechange(name_fieldvalue)
function namechange(name_fieldvalue,name_fieldname,id_val,id_fieldname,table_name)
{
/*
alert(name_fieldvalue);

alert(name_fieldname);
alert(id_val);
alert(id_fieldname);
alert(table_name);
*/

if (name_fieldvalue.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
var url="ajax_namechange.php";
url=url+"?name_fieldvalue="+name_fieldvalue;
url=url+"&name_fieldname="+name_fieldname;
url=url+"&id_val="+id_val;
url=url+"&id_fieldname="+id_fieldname;
url=url+"&table_name="+table_name;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}

Anyone has the idea on this, please help me.

Thanks,
Updated on 2011-02-05T01:40:57Z at 2011-02-05T01:40:57Z by KGopiNarasimha
  • SystemAdmin
    SystemAdmin
    1140 Posts
    ACCEPTED ANSWER

    Re: Ajax calling not encoding in utf-8(ie) problem

    ‏2010-09-09T14:15:34Z  in response to muba
    You've to encode the query string. Can do it like this.
    
    var url=
    "ajax_namechange.php"; url+=
    "?name_fieldvalue="+encodeURI(name_fieldvalue); url+=
    "&name_fieldname="+encodeURI(name_fieldname); url+=
    "&id_val="+encodeURI(id_val); url+=
    "&id_fieldname="+encodeURI(id_fieldname); url+=
    "&table_name="+encodeURI(table_name);
    
    • KGopiNarasimha
      KGopiNarasimha
      2 Posts
      ACCEPTED ANSWER

      Re: Ajax calling not encoding in utf-8(ie) problem

      ‏2011-02-05T01:40:57Z  in response to SystemAdmin
      hi i am facing the same problem in jsp. when i am passing the chinese charactres as query parameters for a jsp page i am unable to retrive from the request object. simply it is giving empty string. please help on this.
      xmlhttp.open("post","test.jsp?chinese="+chinese,true);
      here chinese contains some chinese characters at that time i try get the value in test.jsp like
      String reqData1 = request.getParameter("chinese");

      if i pass chinese value like 利毀損 it is not at all retrived in test.jsp, if i pass any englsih data it is retrived properlly. please suggest to solve this issue ASAP. currently we are unable to process further in IE 6.0