开发者

Posting data with jQuery tabs ajaxoptions

I'm using the following code to initialize my tabs

 $('#tabs').tabs({
        fx: {
            opacity: 'toggle',
            duration: 'fast'
        },
        select: function () {
            $(this).tabs("option", {
                ajaxOptions: { data: vehicleJson }
             });
        },
        ajaxOptions: {
            type: 'post', 
            success: function(){
                alert('onSuccess');
            }, 
            error: function(){
                alert('onFail');
            }
        }, 
        spinner: ''
    }

In my controller I have:

[HttpPost]
public PartialViewResult Intervals(string vehicleJson)
{
    return PartialView("_Intervals");
}

If I remove the [HttpPost] attrib, it seems to work ok, except it is not a 'post' which I need. Basically I'm trying to pass a json object up to a post. What am I doing wrong? Here is the initial HTML for my tabs

<ul id="ul-tabs">
    <li><a href="/maintenance/Tabs/Intervals" title="Intervals">Intervals</a></li>
    <li><a href="/maintenance/Tabs/Lifetime" title="Lifetime Services">Lifetime Services</a></li>
    <li><a href="/maintenance/Tabs/Locator" title="Locator">Locator</a></li>
    <li><a href="/maintenance/Tabs/Procedures" title="Procedures">Procedures</a></li>
    <li><a href="/maintenance/Tabs/Specifications" title="Specif开发者_C百科ications">Specifications</a></li>
    <li><a href="/maintenance/Tabs/Reset" title="Reset">Reset</a></li>
</ul>

How do I correctly force the links to do a post rather than a get? I want to use the javascript data on the server side.

Thanks for a tips or advice,

Cheers,

~ck in San Diego


You are overwriting the ajaxOptions on tab select.

This line:

$(this).tabs("option", { ajaxOptions: {data: vehicleJson}});

Will overwrite your previously set options and cause tabs to use jQuery ajax defaults (type="GET").

You could fix it like this:

var tabAjaxOpts = { 
    type:'post', 
    success:function(){alert('onSuccess');}, 
    error:function(){alert('onFail');}
};

$('#tabs').tabs({
    fx: {
        opacity: 'toggle',
        duration: 'fast'
    },
    select: function () {
        tabAjaxOpts.data = vehicleJson;
        $(this).tabs("option", { ajaxOptions: tabAjaxOpts});
    },
    ajaxOptions: tabAjaxOpts
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜