All pastes #592782 Raw Edit

Untitled

public text v1 · immutable
#592782 ·published 2007-06-27 22:39 UTC
rendered paste body
== dispatch.html ==
<html>
<head>
<script>
function test() {
  $.get(
    '/request.php',
    function(data) {
      resp = eval('(' + data + ')');
      if (resp.status != 'ok') {
        alert('Error: ' + resp.msg);
        return;
      }
      $('#show').html(resp.data);
    }
  }
}
</script>
</head>
<body>
<span onclick="test();">trigger</span>
<div id="show"></div>
</body>
</html>

== request.php ==
<?php
// do something
$result = mysql_query("...");
$resp = array();
if (!$result) {
  $resp['status'] = 'error';
  $resp['msg']    = mysql_error();
  echo json_encode($resp);
  exit;
}
$data = mysql_fetch_array($result);
$resp['status'] = 'ok';
$resp['data']   = $data['whatever'];
echo json_encode($resp);
exit;
?>