客户端方法
function callService(addr,port,service,tabId) { //检查数据的完整性 if(0>getServiceInfo(addr,port,service)) { return; } var Addr = document.getElementById(addr).value; var Port = document.getElementById(port).value; var Service = document.getElementById(service).value; var param = formatTableData(tabId,"dataset"); $.ajax({ url:"<?index.php/gearman/Ajax", type : 'POST', data : {curAddr:Addr, curPort:Port, curService:Service, curParam:param}, dataType : 'text', contentType : 'application/x-www-form-urlencoded', async : false, success : function(mydata) { alert("success"); alert(mydata); var show_data = "<h1>result:" + mydata + "</h1>"; $("#result").html(show_data); }, error : function() { alert("calc failed"); } }); }
服务端如何响应
<?php class GearmanController extends Controller { public function actionAjax() { $addr = Yii::app()->request->getParam('curAddr'); $port = Yii::app()->request->getParam('curPort'); $service = Yii::app()->request->getParam('curService'); $param = Yii::app()->request->getParam('curParam'); echo $addr . $port . $service . $param; } } ?>