主要介紹下如何編寫簡單的php接口,以及使用js/jquery的ajax技術調用此接口。
Php接口文件(check.php):
<?php $jsonp_supporter = $_GET[‘callback’]; $p_name=$_GET[‘p_name’]; $result=array(‘err’=>0,’data’=>$p_name); echo $jsonp_supporter,”(“.json_encode($result).”)”; ?>
Js/jquery通過ajax技術調用接口:
$.get(“http://***/check.php”,{p_name:’ddd’},function(data){
console.log(data.data); },’jsonp’);
這里使用了query中的get方法與接口進行數據交互。