Reputation: 85765
I have some tabs that I load the content up via ajax. I am wondering is there away to look at the response of the ajax call before it loads the content into the tabs?
I want to see if any errors occurred. For instance the tab contents might need the users Id but for some reason that was null. In my code that I have I have stuff that actually checks for these things and if this happens puts it in a validation error.
I usually return the errors back as a json result and use a dialog box to display the error.
So I would like to check the ajax call from the tab and see if it is a validation error(json response) and if has validation errors stop loading the tab and popup a dialog box.
So does jquery ui tabs have something like this? Or do I have to use http status code and set a status code error?
Upvotes: 0
Views: 320
Reputation: 78667
You can use the ajaxOptions to supply a complete function which will allow you to look inside the response. The exact args passed to the complete event depend on which version of jQuery you are using.
function checkResponse(args){
//interrogate the response and decide what to show the user
}
$( ".tabs" ).tabs({ ajaxOptions: { complete: checkResponse } });
Upvotes: 1