ajax + php

Language/PHP 2010. 10. 19. 14:59
※. php 5  이상은 자체 함수 지원, 이하는 JSON.php 필요
quickstart_h.php


<?
 header("Content-Type: text/html; charset=KS_C_5601-1987");
 header("Cache-Control:no-cache");
 header("Pragma:no-cache");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>AJAX with PHP: Quickstart</title>
    <script type="text/javascript" src="quickstart.js"></script>
  </head>
  <body onload='process()'>
    Server wants to know your name:
    <input type="text" id="myName" />
 <input type="text" name="test[]" value="aaa" />
 <input type="text" name="test[]" value="bbb" />
 <input type="text" name="test[]" value="ccc" />
 <input type="text" name="test[]" value="ddd" /> 
   
 <div id="divMessage" />
  </body>
</html>


quickstart.js



<?
 header("Content-Type: text/html; charset=KS_C_5601-1987");
 header("Cache-Control:no-cache");
 header("Pragma:no-cache");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>AJAX with PHP: Quickstart</title>
    <script type="text/javascript" src="quickstart.js"></script>
  </head>
  <body onload='process()'>
    Server wants to know your name:
    <input type="text" id="myName" />
 <input type="text" name="test[]" value="aaa" />
 <input type="text" name="test[]" value="bbb" />
 <input type="text" name="test[]" value="ccc" />
 <input type="text" name="test[]" value="ddd" /> 
   
 <div id="divMessage" />
  </body>
</html>


quickstart.php

<?php
 require 'JSON.php';
 // create a new instance of Services_JSON
 $json = new Services_JSON();
 // convert a complexe value to JSON notation, and send it to the browser
 $value = array('foo'=>'test', 'bar', array(1, 2, 'baz'), array(3, array(4)));
 $output = $json->encode($value);
 //echo $output;
 // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
 
 $people ='
   { "programmers": [
  { "firstName": "Brett", "lastName":"McLaughlin", "email": "brett@newInstance.com" },
  { "firstName": "Jason", "lastName":"Hunter", "email": "jason@servlets.com" },
  { "firstName": "Elliotte", "lastName":"Harold", "email": "elharo@macfaq.com" }
    ],
   "authors": [
  { "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },
  { "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" },
  { "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" }
    ],
   "musicians": [
  { "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
  { "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }
    ]
   }';
  echo $people;

 
?>

'Language > PHP' 카테고리의 다른 글

basename()  (0) 2010.11.04
chr, ord, mb_strlen(한글 길이 리턴)  (0) 2010.10.27
PHP에서 JSON 사용하기  (0) 2010.10.19
inconv, 인코딩  (0) 2010.10.19
php 파일처리 관련함수  (0) 2010.09.28
: