加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

jsonp试水

发布时间:2020-12-16 18:53:49 所属栏目:百科 来源:网络整理
导读:js这样写: $.ajax({ url: "http://m.o2.qq.com/Api/rerunMonitor",// The name of the callback parameter,as specified by the YQL service jsonp: "callback",// Tell jQuery we're expecting JSONP dataType: "jsonp",// Tell YQL what we want and that

js这样写:

$.ajax({
                    url: "http://m.o2.qq.com/Api/rerunMonitor",// The name of the callback parameter,as specified by the YQL service
                    jsonp: "callback",// Tell jQuery we're expecting JSONP
                    dataType: "jsonp",// Tell YQL what we want and that we want JSON
                    data: {
                        monitorID: monitor_id
                    },// Work with the response
                    success: function( response ) {
                        console.log( response ); // server response
                        vm.isupdate=(vm.isupdate==0?1:0);
                        button.html('重跑');
                        button.prop('disabled',false);
                    }
                });

php这样写:
public function rerunMonitor(){
        $monitorID = $_GET["monitorID"];
        if($monitorID==null||$monitorID==''){
            $ret="monitorID缺失";
        }else{
            $this->load->model('material_model','material');
            $model = $this->material;
            $data  = $model->apiGetMonitor($monitorID);
            $date=$data[0]['date'];
            $job=$data[0]['job'];
            $cmd = "/usr/local/php/bin/php /data/www/m.o2.qq.com/application/shell/$job.php $date";
            $ret = exec($cmd);
        }
        $callback=$_GET['callback'];
        echo $callback."('$ret')";
    }

成功,cosole.log输出了php服务器传来的response。

参见https://learn.jquery.com/ajax/working-with-jsonp/

http://justcoding.iteye.com/blog/1366102/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读