Skip to content

Instantly share code, notes, and snippets.

@ikennaokpala
Created February 13, 2011 14:14
Show Gist options
  • Save ikennaokpala/824713 to your computer and use it in GitHub Desktop.
Save ikennaokpala/824713 to your computer and use it in GitHub Desktop.
Login status switch with Jquery Ajax
$(document).ready(function(){
$.each($.browser, function(i, val) {
if(i=="mozilla")
// alert("Ikenna Do stuff for firefox 3 Now now")
$('#header').before('<br/><br/>');
});
$("#loading").ajaxStart(function(){
$(this).append("<p><img src='/images/ajax-loader-2.gif' border='0' align='center' /></p>");
});
$("#listlogin").ajaxSuccess(function(evt, request, settings){
$("#loading").hide();
$(this).fadeIn(2000);
});
$.ajax({
type: "GET",
url: "flashservice.php?xPage=globalVars.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('property').each(function(){
// var id = $(this).attr('id');
var forename = $(this).find('forename').text();
var surname = $(this).find('surname').text();
var myhome = $(this).find('myhome').text();
var mycart = $(this).find('mycart').text();
var logoutroute = $(this).find('logoutroute').text();
var loggedinstatus = $(this).find('loggedinstatus').text();
if (loggedinstatus == "Y"){
$('#addfs').before('<em>'+forename+' '+surname+'</em>');
$('<li class="account"></li>').html('<a href="'+myhome+'">'+forename+'\'s account</a>').appendTo('#listlogin').insertBefore('#hdform');
$('<li class="logout"></li>').html('<a href="'+logoutroute+'" >logout</a>').appendTo('#listlogin').insertBefore('#hdform');
;
$('<li class="vb"></li>').html('<a href="'+mycart+'">view basket</a>').appendTo('#listlogin').insertBefore('#hdform');;
}else{
$('<li class="login"></li>').html('<a href="'+myhome+'">login</a>').appendTo('#listlogin').insertBefore('#hdform');
$('<li class="vb"></li>').html('<a href="'+mycart+'">view basket</a>').appendTo('#listlogin').insertBefore('#hdform');
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment