C H A P T E R 03
CHAPTER 03 03-01 03-01-01 Win m1 f1 e4 e5 e6 o8 Mac m1 f1 s1.2 o8 Linux m1 f1 k3 o8 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <TITLE>AJAX</TITLE> <!-- Ajax jslb_ajax.js --> <script languege = "JavaScript" src = "../../lib/jslb_ajax.js" charset = "utf-8"></script> <script language = "JavaScript"> 82
03-01 <!-- // ( ) function on_loaded1(oj) { // var res = decodeuricomponent(oj.responsetext) } // alert(res) //--> </script> <form> <input type = "button" value = "test.txt, " onclick = "sendrequest(on_loaded1,'','get','./test.txt',true,true)"> </form> IE 6 Mozilla Firefox UTF 8 Opera 8 Safari 1 1 Konqueror 3 UTF 8 encodeuri UTF 8 encodeuri IE Firefox javascript:document.write(encodeuri(' ')) 83
CHAPTER 03 nn n 16 %EC%9D%B4%EC%A0%9C%20%EC%9D%BD%EC%96%B4%20%EB%93%A4%EC%98%80%EC%8A%B5 %EB%8B%88%EB%8B%A4 URL responsetext 03 01 02 responsexml responsetext UTF 8 Konqueror Opera OmniWeb Safari Konqueror responsexml 84
03-01 COLUMN URL http://www.mozilla.com/ 85
CHAPTER 03 86
03-01 03-01-02 Win m1 f1 e4 e5 e6 o8 Mac m1 f1 s1.2 o8 Linux m1 f1 k3 o8 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <TITLE>AJAX</TITLE> <!-- Ajax jslb_ajax.js --> <script languege = "JavaScript" src = "../../lib/jslb_ajax.js" charset = "utf-8"></script> <script language = "JavaScript"> <!-- // ( ) function on_loaded1(oj) { // var xmldoc = oj.responsexml //testdata var nodes = xmldoc.getelementsbytagname("testdata") // testdata firstchild alert(nodes[0].firstchild.nodevalue) 87
CHAPTER 03 } //--> </script> <form> <input type = "button" value = "test.xml, " onclick = "sendrequest(on_loaded1,'','get','./test.xml',true,true)"> </form> <?xml version="1.0" encoding="utf-8"?> <testdata> XML </testdata> 03 01 01 responsetext responsexml UTF 8 Ajax Konqueror 3 3 UTF 16BOM Konqueror 3 4 responsexml DOM DOM test xml testdata getelementsbytagname 0 testdata firstchild XML encoding xml version= 1 0 encoding= UTF 8 XML XML JavaScript 06 02 DOM 88
03-01 03-01-03 Win m1 f1 e4 e5 e6 o8 Mac m1 f1 s1.2 o8 Linux m1 f1 k3 o8 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <TITLE>AJAX</TITLE> <!-- Ajax jslb_ajax.js --> <script languege = "JavaScript" src = "../../lib/jslb_ajax.js" charset = "utf-8"></script> <script language = "JavaScript"> <!-- // ( ) function on_loaded1(oj) { //, eval eval("var res = "+oj.responsetext) // JSON test1 89
CHAPTER 03 alert(res.test1) } //--> </script> <form> <input type = "button" value = "test.data, JSON " onclick = "sendrequest(on_loaded1,'','get','./test.dat',true,true)"> </form> { } "test1": "hello1", "test2": "hello2" 03 01 01 eval JavaScript M E M O 90
03-01 COLUMN URL Introducing JSON var oj = { " ": " ", " ": function (){ alert('this is method') } } var ary = [ " 1", " 2", " 3"] 91
CHAPTER 03 03-02 03-02-01 Win m1 f1 e4 e5 e6 o8 Mac m1 f1 s1.2 o8 Linux m1 f1 k3 o8 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <TITLE>AJAX</TITLE> <!-- Ajax jslb_ajax.js --> <script languege = "JavaScript" src = "../../lib/jslb_ajax.js" charset = "utf-8"></script> <script language = "JavaScript"> <!-- 92
03-02 // ( ) function on_loaded1(oj) { // var res = decodeuricomponent(oj.responsetext) } // alert(res) //--> </script> <form> <input type = "button" value = "PHP ' ', " onclick = "sendrequest(on_loaded1,'&data= ','POST','./echo.php',true,true)"> </form> <?php //POST $data = $_POST['data']; $data = " --".$data."--."; // UTF-8 //$data = mb_convert_encoding($data,"utf-8"); // HTML ( < < ) $data = htmlspecialchars($data,0,"utf-8"); //URI $data = rawurlencode($data); // UTF-8 mb_http_output ( 'UTF-8' ); 93
CHAPTER 03 // echo ($data);?> sample html sendrequest data= POST PHP echo php POST[ data UTF 8 URI echo URI responsetext Safari KHTML URI JavaScript decodeuricomponent decodeuri UTF 8 Ajax decodeuricomponent PHP mb convert encoding UTF 8 rawurlencode URI sample htm UTF 8 mb convert encoding M E M O 94
03-02 COLUMN //POST $data = $_POST['data']; $data = " --".$data."--."; //POST $data = mb_convert_encoding($_post['data'], "EUC-KR",'UTF-8'); $data = " --".$data."--."; // UTF-8 $data = mb_convert_encoding($data,"utf-8", "EUC-KR"); 95
CHAPTER 03 03-02-02 Win m1 f1 e4 e5 e6 o8 Mac m1 f1 s1.2 o8 Linux m1 f1 k3 o8 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <TITLE>AJAX</TITLE> <!-- Ajax jslb_ajax.js --> <script languege = "JavaScript" src = "../../lib/jslb_ajax.js" charset = "utf-8"></script> <script language = "JavaScript"> <!-- // ( ) function on_loaded1(oj) { // var res = decodeuricomponent(oj.responsetext) 96
03-02 } // alert(res) //--> </script> <form> <input type = "button" value = "Perl ' ', " onclick = "sendrequest(on_loaded1,'&data= ','GET','./echo.cgi',true,true)"> </form> #!/usr/bin/perl use Jcode; # GET ($dmy, $data) = split(/data=/, $ENV{'QUERY_STRING'}); # URL $data =~ s/%([0-9a-fa-f][0-9a-fa-f])/chr(hex($1))/ego; # $msg = " Perl --".$data."--.\n"; # UTF-8 &Jcode::convert(\$msg,'utf8'); # URI $msg =~ s/([^a-za-z0-9'-_!~*.()])/'%'. unpack('h2', $1)/eg; # Content-type charset UTF-8 print "Content-type: text/html;charset=utf-8\n\n"; # print "$msg \n"; 97
CHAPTER 03 sample html sendrequest data= GET Perl echo cgi ENV QUERY STRING URI UTF 8 URI print URI 03 02 01 PHP PHP URL Perl ENV QUERY STRING JavaScript decodeuricomponent decodeuri UTF 8 Ajax decodeuricomponent Perl 98