我们主要是采用json传输数据的方式处理
JSONP(JSON with Padding)是一个非官方的协议,它允许在服务器端集成Script tags返回至客户端,通过javascript callback的形式实现跨域访问(这仅仅是JSONP简单的实现形式)
<!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> <Meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <Meta http-equiv="refresh" content="url=https://www.serve888.com/serve888/chatClient/chatBox.jsp?companyID=217"> <title>服务中心</title> <style> html,body{margin:0;padding:0;} </style> <script type="text/javascript" src="scripts/jquery.js"></script> </head> <body> <script language="javascript" type="text/javascript"> $(function(){ var url = "http://program/test/test.PHP?username=laobi&jsoncallback=?"; $.ajax({ url: url,type: 'GET',dataType: 'json',//timeout: 1,success: function(data){ alert(data.status); } }); }); </script> </body> </html>
test.PHP
$arr = array('username'=>trim($_GET['username']),'status'=>'1'); echo trim($_GET['jsoncallback']).'('.json_encode($arr).')';