我想去参观某个休息区。你知道吗
$.ajax({
type: "POST",
url: url + "result/" + ticket_id,
success: function(data) {
setTimeout(function(){pollResponse(url,data.id);}, 3000);
}
});
这很管用。它访问URI,views函数完成它的工作。因此,继续success
它将转到新的URI。你知道吗
function pollResponse(url, id)
{
$.getJSON(url + "status/" + id, {},
function(data) {
if (data.report == null)
{
console.log(data.status_response);
setTimeout(function(){pollResponse(url, id);}, 3000);
}
else
console.alert('DONE!');
}
);
};
如果URI没有返回report
作为数据的一部分(或者为空),那么我们将在3秒钟后再次询问。你知道吗
但是在控制台中打印日志之后,响应将以[200] OK
停止。
它不再询问服务器。你知道吗
我对Python的views函数所做的就是
from cornice import Service
status = Service(name='status',
path=root+'/status/{some_id}',
description=status_desc)
@status.get()
def get_status(request):
// do something
if (...):
return {'report': ''}
else:
return {'report': 'NOT EMPTY')
结果中可能存在解析问题或跨域问题。尝试更改代码以直接使用
ajax
函数:这样您就可以看到响应是否导致了错误。如果有解析错误,您可以通过jqXHR.responseText文件关于误差函数,看看有什么问题。你知道吗
jQuery中AJAX的快捷方式函数在很多情况下都会自动出错。这就是为什么我很少使用它们。你知道吗
看起来轮询函数中的
setTimeout
应该是:而不是:
相关问题 更多 >
编程相关推荐