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/

相关文章

AJAX是一种基于JavaScript和XML的技术,能够使网页实现异步交...
在网页开发中,我们常常需要通过Ajax从后端获取数据并在页面...
在前端开发中,经常需要循环JSON对象数组进行数据操作。使用...
AJAX(Asynchronous JavaScript and XML)是一种用于创建 We...
AJAX技术被广泛应用于现代Web开发,它可以在无需重新加载页面...
Ajax是一种通过JavaScript和HTTP请求交互的技术,可以实现无...