'encodeURI'에 해당되는 글 1건

  1. 2009.04.01 검색 url 호출방법(encodeURI)
posted by 준치 2009. 4. 1. 18:47

 url 검색 호출하는 방식
// 검색버튼 클릭으로 통합검색
function TCategorySearch(str)
{
//debugger;
    TotalParameters = str;
    CallFlag = "TCategorySearch";
   
    var nowAddress = decodeURI(DefaultURL);
    var SearchBox = document.all["CategoryTxt"].value;
   
    SearchBox = change(SearchBox);   
   
    httpRequest = getXMLHttpRequest();
    httpRequest.onreadystatechange = SearchSaveCall;
    httpRequest.open("GET",nowAddress + "?keyword=" + encodeURI(SearchBox),true);
    httpRequest.send(null);
}

변환되는거 예)
idx 문자 escape charCode encodeURI

0 A A 65 A

1 a a 97 a

2 ? %3F 63 ?

3 ㄱ %u3131 12593 %E3%84%B1

4 음 %uc74C 51020 %EC%9D%8C

<body>

<script>

 str = "Aa?ㄱ음";

 v = "<table border = 1>

 <tr>

  <td> idx </td>

  <td>문자</td>

  <td>escape </td>

  <td>charCode </td>

  <td>encodeURI</td>

 </tr>

 for(i = 0; i<str.length; i++){

  v+ = "<tr>;

  v+ = "<td>"+i+"</td><td>"+str.charAt(i)+"</td> <td>"+escape(str.charAt(i))+"</td><td>"+str.charcodeAt(i)+"</td><td>"+encodeURI(str.charAt(i))+"</td>;

  v+ = "</tr>";

 }

 v+ = "</table>";

 document.write(v);

</script>

다름방법

"%"를 붙이고

Unicode 판별하여 "u"를 붙이고

charCodeAt으로 escape번호를 구한후 toString(16)으로 16진수를 변환한 후 toUpperCase로

대문자 변환하여 인위적으로 escape문자를 만들어서

해결할 수 있음

<script>

 var str = "fdk?'jh8Aau";

 var esc = "";

 for(var i=0; i < str.length; i++){

  esc = "%"+(escape(str.charAt(i)).match(/%u/g)?"u":"")+str.charCodeAt(i).toString(16).toUpperCase();

  document.write("<br>" +i+"=========================="

    +"<br>원래문자 : "+str.charAt(i)

    +"<br>escape문자: "+esc

    +"<br>다시원래대로:"+unescape(esc));

 }

</script>