jsonp试水

前端之家收集整理的这篇文章主要介绍了jsonp试水前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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/

原文链接:https://www.f2er.com/json/289162.html

猜你在找的Json相关文章