我们正在数据库中存储事件。一个事件可能是一个页面命中和保存/更新等。从内部控制器动作,这是美丽的发生。
我有3个链接,当点击这些链接时,我想在db中存储一个事件。我希望通过jquery/ajax在幕后通过jquery/ajax来存储事件,然后执行response.redirect,而不是让用户进行一般操作。现在,当用户单击链接时,应该发生两件事
我只想让用户点击链接,然后用户进入预定的页面。幕后处理不应该让用户在页面上停留一两秒钟,而代码正在等待来自远程操作的响应。我是否需要等待ajax请求的完成,还是只需在jquery操作中添加“返回真”?由于用户将被带到下一页,我的ajax请求是坏的还是停止的?在firebug中,当用户在ajax请求完成之前单击页面上的某个链接时,我看到ajax进程将中止。我怎么能做这样的事呢?
样本代码:
$(document).ready(function() {
$("a[custom-event]").on('click', function () {
var label = $(this).attr("custom-event");
var value = $(this).attr("custom-event-value");
DoSomeAjaxProcessing('event', 'click', label, value); //don't want this to go bad if redirection happens immediately
return true; //return true so that the browser can send the user to the href location
});
});更新1:
像这样的东西会为我飞吗。我也要测试和更新。
$(document).ready(function() {
$("a[custom-event]").on('click', function () {
var label = $(this).attr("custom-event");
var value = $(this).attr("custom-event-value");
(new Image).src = someurl+"?label="+label+"&value="+value+"&type=event&action=click";
return true; //return true so that the browser can send the user to the href location
});
});发布于 2014-11-18 07:20:20
如果你试图用你的服务器记录一个事件,你将不得不付出一些代价。您不能异步地调用服务器来记录事件并同时为该链接提供目标服务。
正如你所建议的那样,你提出的两条道路是不能令人满意的:
在Stack,我们也使用"events“来跟踪用户的操作,但是我们可以在目标的控制器级别进行很大程度的跟踪。
例如,如果有一个签出流将用户从/home路由带到/login路由,我们将在为/login视图服务的控制器的开头跟踪该事件。
[Route("/login")]
public virtual ActionResult Login()
{
// Tracking code here, probably passing in the referrer
return View();
}https://stackoverflow.com/questions/26983113
复制相似问题