We want all of our AJAX calls in our web app to receive JSON-encoded content. In most places this is already done (e.g. in modals) and works fine.
However, when using j
I got stuck with this problem recently, so just in case someone has been looking for help with this kind of issue more recently, I thought it would be useful to re-open this discussion. I'm working with jQuery 1.8.2 and jQuery UI 1.9.2. I found the best way to do this with the latest version of jQuery UI was to return false from the beforeLoad event handler and send a getJSON request with the URL specified in the relevant tab.
HTML markup:
Tabs invocation code:
$(function () { $("#tabs").tabs({ beforeLoad: function (event, ui) { var url = ui.ajaxSettings.url; $.getJSON(url, function (data) { ui.panel.html(data.text); }); return false; } }); });When the
beforeLoadhandler returns false, the normal functionality of displaying the HTML retrieved from the URL defined in the tab is disabled. However, you still have access to theeventanduiobjects passed to thebeforeLoadhandler. You get the URL from the tab with this syntaxui.ajaxSettings.urland then display the data returned by thegetJSONrequest as shown in the Content via Ajax example:ui.panel.html(data.text);In my case, it's data.text because the JSON I'm retrieving contains two properties
headerandtext.