$.ajax({ url: "http://example.com/load_data.php", dataType: "jsonp", jsonpCallback: 'jsonCallback', success: function(data){ alert("success"); }, error:function(){ alert("failure"); } });
PHP code
header("Content-Type: application/json"); require_once "connect_db.php"; $sql = "select * from Table"; $res = mysql_query($sql) or die(mysql_error()); $data = array(); while($row = mysql_fetch_array($res)){ array_push($data,$row); } echo $_GET['callback'].'('.json_encode($data).')';
ไม่มีความคิดเห็น:
แสดงความคิดเห็น