如何将鼠标事件发送到ajaxSetup beforeSend?
我有几个调用 Ajax 功能的按钮(提交联系表单、提交时事通讯、检查用户是否有效/已注册、检查用户状态等...)
我使用 ajaxSetup 来显示加载对话框,每次有人单击其中的按钮时命令告诉他等待。这是我的代码:
$('#submit').click(function(e) {
// easily done but it's repetitive
$('#loadingDiablog').css({'top':e.pageY+'px','left':e.pageX+'px'});
});
$.ajaxSetup({
beforeSend: function(jqXHR, settings) {
$('#loadingDiablog').css({'top':e.pageY+'px','left':e.pageX+'px'}); // e is not defined here
}
});
所以为了不重复相同的代码,我怎样才能将鼠标(在 .click(function(e)
上传递)传递给 AjaxSetup 中的 beforeSend ?
谢谢
I have few buttons that call Ajax functions (submit contact form, submit newsletter, check if user is valid/already registered, check user status etc...)
I use the ajaxSetup to show a Loading Dialog every time someone click on a button in order to tell him to wait. Here's my code:
$('#submit').click(function(e) {
// easily done but it's repetitive
$('#loadingDiablog').css({'top':e.pageY+'px','left':e.pageX+'px'});
});
$.ajaxSetup({
beforeSend: function(jqXHR, settings) {
$('#loadingDiablog').css({'top':e.pageY+'px','left':e.pageX+'px'}); // e is not defined here
}
});
So in order to not repeat the same code, How can I pass the mouse even ( passed on .click(function(e)
) to the beforeSend in the AjaxSetup?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种快速的方法是向所有要显示加载程序的提交按钮添加一个类,并在单击其中任何一个按钮时触发它。
更新:
One quick way of doing it would be to add a class to all your submit buttons that you want to show the loader for and just fire it when any of them are clicked.
UPDATE: