我在用户面板中有一个加载程序,它正在等待用户移动设备的响应。不幸的是,我完全不知道如何从移动设备获得请求,并实时更新页面内容。
现在我遇到的问题是,我正在通过ajax将数据从视图页面发送到我的控制器函数。。。。然后在Controller函数中,我将从ajax函数获得的一些数据发送到实用程序类中的另一个函数,然后将结果返回到ajax函数。。。。每当我收到来自控制器函数的响应时,我就会启动loader/preloader/ajax微调器。。。现在,在我从android发送一个变量之后。。。所以在android响应到来后,我想停止加载程序。。。所以我不知道如何具体调用ajax函数和来自控制器的响应
有两种方法可以实现
首先,我直接从android调用javascript函数,然后获取值。第二,或者我从控制器调用javascript函数,并在ajax函数中发送值。。不知道这是否可能。。。
我的js函数
function openPrompt()
{
var cancelled = true;
var lock='lock';
$.modal.prompt('Enter message :', function(value)
{
$.ajax({
type:"POST",
data:{value:value,lock:lock},
url:"/allsecure/api/lock/",
success : function(data) {
//start spinner
},
error : function() {
alert("error");
}
});
}, function()
{
});
};
控制器功能
public function lock(){
if( $this->request->is('ajax') ) {
$message = $this->request->data('value');
$lock = $this->request->data('lock');
$this->loadModel('Userinfo');
$userid = $this->Auth->User('idUser');
$key = $this->Userinfo->getKey($userid);
$apiKey = "1234567890";
$resp = AllSecure::sendNotification($apiKey, array($key), array('message' => $lock, 'tickerText' =>$message));
echo $resp; //after this response i am starting the loader
}
}
function android(){
// here i am getting the variable from android
$json = $this->request->data('json');
$data = json_decode($json, TRUE);
openPrompt()//here i want to call the javascript function and want to send the value of android to the javascript
}
或者有什么更好的方法可以做到这一点???
如果您想从服务器执行客户端javascript,您可以执行与JSONP类似的操作。其中响应是在客户端中执行的JSON数据包装javascript函数。