Jquery 选项卡:更改选项卡单击上的 ajax 数据
我已经使用 jquery 选项卡通过 ajax 加载数据,但是当用户单击选项卡时,我需要向 url 添加一些参数。我事先不知道参数,因为它们来自用户填写的表单。因此,我尝试了类似以下代码的操作,但无法正常工作:
<div id="tabs">
<ul>
<li><a href="${tab1_url}">Tab 1</a></li>
<li><a href="${tab2_url}">Tab 2</a></li>
<li><a href="${tab3_url}">Tab 3</a></li>
</ul>
</div>
我将表单序列化到数组中,并将该数组连接到包含静态数据的数组。
var staticData = [{name:'id',value:'${myId}'}];
$("#tabs").tabs({
var $tabs = $("#tabs").tabs({
ajaxOptions: { data: staticData},
select: function(event, ui) {
var dynamicData = $("#common_form").serializeArray();
var dataToSend = staticData.concat(dynamicData);
$("#tabs").tabs("option", "ajaxOptions", { 'data': dataToSend });
return true;
}
});
});
但这不会在创建选项卡后更新ajax数据(我看到用Firebug发送的请求,它只包含初始参数)。
当用户单击选项卡时,如何更改ajax数据?
谢谢
已编辑:现在使用此代码可以工作
I have used jquery tabs for loading data with ajax, but I need to add some parameters to the url when the user clicks in a tab. I don't know the parameters in advance because they come from a form which has been filled by the user. So I've tried something like the following code, but I don't get it working:
<div id="tabs">
<ul>
<li><a href="${tab1_url}">Tab 1</a></li>
<li><a href="${tab2_url}">Tab 2</a></li>
<li><a href="${tab3_url}">Tab 3</a></li>
</ul>
</div>
and I serialize the form in an array and join the array to the array containing the satic data.
var staticData = [{name:'id',value:'${myId}'}];
$("#tabs").tabs({
var $tabs = $("#tabs").tabs({
ajaxOptions: { data: staticData},
select: function(event, ui) {
var dynamicData = $("#common_form").serializeArray();
var dataToSend = staticData.concat(dynamicData);
$("#tabs").tabs("option", "ajaxOptions", { 'data': dataToSend });
return true;
}
});
});
but this doesn't update the ajax data after the tabs are created (I'm seeing the request sent with Firebug and it only includes the initial params).
How can I change the ajax data when the user clicks the tab?
Thanks
EDITED: now with this code works
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您正在寻找的是“url”方法:
http://jqueryui.com /demos/tabs/#method-url
您的代码看起来像这样:
I think that what you are looking for is the "url" method :
http://jqueryui.com/demos/tabs/#method-url
You code would look something like that :
这对我有用,但如果我需要前 100 个选项卡,我需要输入所有 100 个选项卡的 URL。
This work for me but if i need for ex 100 tabs i need to put in all 100 tabs url.
Jquery 代码...
Jquery code...