Note that there are some explanatory texts on larger screens.

plurals
  1. POrealtime javascript request from android or call javascript function from Controller Cakephp/php
    text
    copied!<p>I have a loader in user panel which is waiting for a response from user's mobile device. Unfortunately i'm compeletly blank on how to get the request from mobile device, and update the page content real time.</p> <p>right now the problem i have is i am sending data from view page to my Controller function through ajax .... then in Controller function i am sending some data which i get from the ajax function to the other function which is in utility class and then returning the result to the ajax function.... and whenever the i receive the response from the controller function then i am starting the loader/preloader/ajax spinner ... now after the i am sending a variable from android ... so after the android response comes i want to stop the loader ... so i dont know how to i call the ajax function specifically and the response from controller </p> <p>there can be two ways to acheive this </p> <p>1st either i call directly the javascript function from android and then grab the value . 2nd or i call the javascript function from controller and send the value in ajax function ..dont know if it is possible ... </p> <p><strong>my js function</strong></p> <pre><code>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() { }); }; </code></pre> <p><strong>Controller function</strong></p> <pre><code> public function lock(){ if( $this-&gt;request-&gt;is('ajax') ) { $message = $this-&gt;request-&gt;data('value'); $lock = $this-&gt;request-&gt;data('lock'); $this-&gt;loadModel('Userinfo'); $userid = $this-&gt;Auth-&gt;User('idUser'); $key = $this-&gt;Userinfo-&gt;getKey($userid); $apiKey = "1234567890"; $resp = AllSecure::sendNotification($apiKey, array($key), array('message' =&gt; $lock, 'tickerText' =&gt;$message)); echo $resp; //after this response i am starting the loader } } function android(){ // here i am getting the variable from android $json = $this-&gt;request-&gt;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 } </code></pre> <p>or there is any better approach to do this ???</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload