jQuery Dashboard 中的 Widget 中的 Ajax 调用
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我之前所说,一个实例会有所帮助,但我仍然查看了这段代码,一切看起来都很好,假设你的 ajax 调用总是返回它应该返回的内容(你是否使用 firebug 或其他东西进行了验证?)。您应该将这段代码放在 dom 就绪函数中:
而不是在回调中设置它。所以你只需要调用 $('#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:
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