重庆百度seo整站优化,上海文娱场所暂停营业,郑州网站网络推广公司,友情链接多久有效果定义来源#xff1a;http://zh.wikipedia.org/wiki/JSONP JSONP#xff08;JSON with Padding#xff09;是资料格式 JSON 的一种“使用模式”#xff0c;可以让网页从别的网域要资料。另一个解决这个问题的新方法是跨来源资源共享。 由于同源策略#xff0c;一般来说位于…定义来源http://zh.wikipedia.org/wiki/JSONP JSONPJSON with Padding是资料格式 JSON 的一种“使用模式”可以让网页从别的网域要资料。另一个解决这个问题的新方法是跨来源资源共享。 由于同源策略一般来说位于 server1.example.com 的网页无法与不是 server1.example.com 的服务器沟通而 HTML 的 script 元素是一个例外。利用 script 元素的这个开放策略网页可以得到从其他来源动态产生的 JSON 资料而这种使用模式就是所谓的 JSONP。用 JSONP 抓到的资料并不是 JSON而是任意的 JavaScript用 JavaScript 直译器执行而不是用 JSON 解析器解析。 下面是我在一个项目中的应用 描述域名dev.uc.everychina.com 要获得域名 dev.members.everychina.com下的数据 dev.members.everychina.com的服务器端代码 class JsController extends CController {
public function actionIndex() {$callback isset($_GET[callback]) ? $_GET[callback] : ;$result array();$userinfo Intf_Client_Uc_User::instance()-getLoginUser();$cid Everychina_Member::instance()-getCid($userinfo[uid]);//公司展厅评分$room_score Ec_RoomScore::getInstance();//获得展厅老的评分$update_status true;//重新评分if(isset($_GET[action]) $_GET[action]update) { $score_res $room_score-getScoreInfo($cid); $room_score-updateScoreResult($cid,$score_res);$update_status true; }$result[status] $update_status;$res $room_score-getScoreResult($cid); $result[score] $room_score-getScoreResultView($res[score]);if ($callback) {$js json_encode($result);echo $callback( ($js) );;} } 域名 dev.uc.everychina.com 下前端调用html a idupdate_score href# onclickajaxUpdateScore();return false;update score/a
div idmember_score/div javascript function ajaxUpdateScore(){if(document.getElementById(member_score_script)) {var score_script document.getElementById(member_score_script); document.body.removeChild(score_script); }var score_script document.createElement(script);score_script.id member_score_script;score_script.src http://dev.members.everychina.com/index.php?rjs/indexcallbackshow_scoretnew Date().getTime();document.body.appendChild(score_script);}function show_score(json) { if(json.status true) {var html plevel:json.score.level/p;html pmsg:json.score.msg/p;html pscore:json.score.score/p;$(#member_score).html(html); }} 转载于:https://www.cnblogs.com/daxian2012/archive/2012/08/15/2640650.html