I have written the following to do AJAX requests in my app:
$(document).ready(function () {
$('ul#ui-ajax-tabs li:first').addClass('selected');
$('#ui-ajax-tabs li a').click(function (e) {
e.preventDefault();
$("#ui-ajax-tabs li").removeClass("selected");
$(this).parents('li').addClass("loading");
var url = $(this).attr("href");
var link = $(this);
console.log(url);
$.ajax({
url: url,
success: function (responseHtml) {
$('div#ui-tab-content').html($(responseHtml).find('div#ui-tab-content > div#ui-ajax-html'));
$(link).parents('li').addClass('selected');
$("#ui-ajax-tabs li").removeClass("loading");
},
error: function () {
$('div#ui-tab-content').html('<div class="message error">Sorry that page doesn\'t exist</div>');
$(link).parents('li').addClass('selected');
$("#ui-ajax-tabs li").removeClass("loading");
}
});
});
});
How would I grab the title from the requested page and use it?
I've thought about something like: var title = $(document).attr('title');
but how do I get the title from the requested page and set that as the new title? Thanks
I am new to jQuery, but I will give it a try anyways:
var newTitle = $(responseHtml).filter('title').text();
And if one of the above works, the current title could be changed by
document.title = newTitle;
Again I am a jQuery and Javascript beginner and just wanted to give it a try :) So excuse me if its stupid and wont work :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With