jQuery Dashboard 中的 Widget 中的 Ajax 调用

发布于 2024-12-06 04:52:51 字数 1010 浏览 0 评论 0原文

我正在使用 jQuery Dashboard 插件来显示 MySql 表信息。我在这些小部件中为每个 mysql 结果提供了按钮来显示表单。该按钮执行 ajax 调用以传入表单 id,然后检索要在 jQuery 对话框中显示的样式化表单信息。问题是,第一次访问仪表板并尝试单击按钮需要多次单击才能检索表单。我在仪表板中有几个使用这种技术的小部件(确切地说是 3 个),并且恰好需要单击 2 次才能让第三个小部件返回表单。这可能是由于不同小部件中的按钮实例造成的吗?我是这么想的,结果用相同的 ajax 代码为每个按钮创建了不同的类。然而,问题仍然存在。这是一个非常烦人的错误,我无法弄清楚,并且仅针对这个错误就已经尝试了 4 天。下面是我的ajax代码:

$(".view_all").click(function(){ var form_id = $(this).attr("id"); $.ajax({ 类型:“获取”, url: "form.php", 数据:“fid =”+ form_id, 发送前:函数(){ $("#loading").show(); }, 成功:函数(消息){ $("#pop_container").html(msg); $("#pop_container").dialog({ 自动打开:假, 身高:750, 宽度:950, 模态:真实, closeOnEscape: false }); $("#pop_container").dialog("打开"); $("#loading").hide();
} }); 返回假; });

对于代码格式不正确,我深表歉意。我尝试过,但没有成功。

无论如何,对此的任何帮助都会非常有帮助。谢谢!

I am using the jQuery Dashboard plugin to display MySql table information. I have within these widgets buttons for each mysql result to display a form. The button performs an ajax call to pass in the form id and then retrieve the styled form information to be displayed in a jQuery dialog. The issue is that the first time visiting the dashboard and trying to click a button requires multiple clicks for the form to be retrieved. I have several widgets in the dashboard that use this technique (3 to be exact) and it just so happens to take 2 clicks before the 3rd will return the form. Could this be due to the button instances in different widgets? I thought so, and as a result made different classes for each button with same ajax code. The problem, however, persists. This is an extraordinarily annoying bug that I CANNOT figure out and have been trying to for 4 DAYS on this 1 bug alone. Below is my ajax code:

$(".view_all").click(function(){
var form_id = $(this).attr("id");
$.ajax({
type: "GET",
url: "form.php",
data: "fid="+form_id,
beforeSend: function(){
$("#loading").show();
},
success: function(msg){
$("#pop_container").html(msg);
$("#pop_container").dialog({
autoOpen: false,
height: 750,
width: 950,
modal: true,
closeOnEscape: false
});
$("#pop_container").dialog("open");
$("#loading").hide();
}
});
return false;
});

My apologies for the code not being formatted well. I tried but it didnt work.

Anyway, any help on this would be extremely helpful. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那支青花 2024-12-13 04:52:51

正如我之前所说,一个实例会有所帮助,但我仍然查看了这段代码,一切看起来都很好,假设你的 ajax 调用总是返回它应该返回的内容(你是否使用 firebug 或其他东西进行了验证?)。您应该将这段代码放在 dom 就绪函数中:

                $("#pop_container").dialog({ 
                    autoOpen: false, 
                    height: 750, 
                    width: 950, 
                    modal: true, 
                    closeOnEscape: false 
                }); 

而不是在回调中设置它。所以你只需要调用 $('#pop_container').dialog('open');在回调中。现在,如果这还不够,而且应该还不够,您可以在 jQuery ($('.view_all').trigger('click')) 中手动触发单击,但这并不是真正的“干净”。不知道这是否有帮助,但如果不完全了解发生了什么,我就无法做更多的事情:P

As i previously said, a live example would have helped but i still took a look at this code and everything seemed pretty alright, assuming you're ajax calls always return what it should return (did you verify with firebug or somethin?). You should put this piece of your code in the dom ready function:

                $("#pop_container").dialog({ 
                    autoOpen: false, 
                    height: 750, 
                    width: 950, 
                    modal: true, 
                    closeOnEscape: false 
                }); 

Instead of setting this in the callback. So you just have to call $('#pop_container').dialog('open'); in the callback. Now if this is not enough, and it shouldn't be enough, you can manually trigger a click in jQuery ($('.view_all').trigger('click')) but this is not really "clean". Don't know if this helps but i can't do more without completely understanding whats going on :P

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文