php 端: demo.php
<?php $result =array('content'=>$_GET['content']); function jsonp($result){ return $_GET['callback'] . '(' . urldecode(json_encode($result)) . ')'; } echo jsonp($result); ?>
客户端:demo.js
<script> $.ajax({ url : 'http://127.0.0.1/demo.php', data :{'content':'this is a test'}, dataType : 'jsonp', jsonp : 'callback', success : function(res) { console.log(res); } }); </script>