i am working on a Cakephp 2.x .
我正在开发一个Cakephp 2.x.
I have a loader/spinner on my view page 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.
我的视图页面上有一个加载器/微调器,它正在等待用户移动设备的响应。不幸的是,我对如何从移动设备获取请求并实时更新页面内容非常空白。
here is the function
这是功能
<script>
var cancelled = true;
$.modal.prompt('Enter message :', function(value)
{
$.ajax({
type:"POST",
data:{value:value},
url:"/cakephp/api/getData/",
success : function(data) {
//i am starting the spinner here ..
here i want to get the value from an android device ..as soon as i receive the value i want to stop the spinner
},
error : function() {
alert("error");
}
});
}, function()
{
});
};
how can i do this?
我怎样才能做到这一点?
1 个解决方案
#1
1
You can do it in three ways:
您可以通过三种方式完成此操作:
1- Using webSocket
it's really real time, you should create a webSocket connection through client with javascript
and server with any webSocket
server such as node.js
or ratchet
. disadvantage of webSocket
is some old browsers doesn't support it.
1-使用webSocket它是非常实时的,您应该通过客户端使用javascript和服务器与任何webSocket服务器(如node.js或ratchet)创建webSocket连接。 webSocket的缺点是一些旧的浏览器不支持它。
2- using Long polling
,it creates connection to server like AJAX
does, but keep-alive
connection open for some time (not long though), during connection open client can receive data from server. Client have to reconnect periodically after connection is closed due to timeouts. On server side it still treated like HTTP
request same as AJAX
. in client side you can use a javascript
library like strophe
and on server side can ejabberd
for long pulling server.
2-使用长轮询,它像AJAX一样创建与服务器的连接,但保持连接打开一段时间(不长),在连接打开客户端可以从服务器接收数据。由于超时,客户端必须在连接关闭后定期重新连接。在服务器端,它仍然像AJAX一样对待HTTP请求。在客户端你可以使用像strophe的javascript库,在服务器端可以ejabberd长拉服务器。
3- using AJAX
in intervals ,you can send a request in intervals to check if any response recieved from user's mobile device in server or not. but it is not really real time.
3-在间隔期间使用AJAX,您可以间隔发送请求以检查是否有任何响应从服务器中的用户移动设备收到。但这不是真正的实时。
#1
1
You can do it in three ways:
您可以通过三种方式完成此操作:
1- Using webSocket
it's really real time, you should create a webSocket connection through client with javascript
and server with any webSocket
server such as node.js
or ratchet
. disadvantage of webSocket
is some old browsers doesn't support it.
1-使用webSocket它是非常实时的,您应该通过客户端使用javascript和服务器与任何webSocket服务器(如node.js或ratchet)创建webSocket连接。 webSocket的缺点是一些旧的浏览器不支持它。
2- using Long polling
,it creates connection to server like AJAX
does, but keep-alive
connection open for some time (not long though), during connection open client can receive data from server. Client have to reconnect periodically after connection is closed due to timeouts. On server side it still treated like HTTP
request same as AJAX
. in client side you can use a javascript
library like strophe
and on server side can ejabberd
for long pulling server.
2-使用长轮询,它像AJAX一样创建与服务器的连接,但保持连接打开一段时间(不长),在连接打开客户端可以从服务器接收数据。由于超时,客户端必须在连接关闭后定期重新连接。在服务器端,它仍然像AJAX一样对待HTTP请求。在客户端你可以使用像strophe的javascript库,在服务器端可以ejabberd长拉服务器。
3- using AJAX
in intervals ,you can send a request in intervals to check if any response recieved from user's mobile device in server or not. but it is not really real time.
3-在间隔期间使用AJAX,您可以间隔发送请求以检查是否有任何响应从服务器中的用户移动设备收到。但这不是真正的实时。