Buying Fix my Ajax script

Discussion in 'Programming' started by lowridertj, Mar 17, 2011.

  1. #1
    I have a code that I was using in facebook as fbml / fbjs and was working perfectly.
    Since they have made changes I figured I would start working on a iframed version however it is not working at all now.

    
      <script src="http://code.jquery.com/jquery-1.5.js"></script>
    	<script type="text/javascript"> 
    
    	healthtimer = document.getElementById("healthtimer");
    	cashtimer = document.getElementById("cashtimer");
    	energytimer = document.getElementById("energytimer");
    	strengthtimer = document.getElementById("strengthtimer");
    	userexp = "";
    
    	
    	//cashmins, healthmins, energymins, strengthmins, seconds, healthtimer, cashtimer, energytimer, strengthtimer
    	function display(){
    
    			 var update = false;
    			 
    			 if (seconds==0){ 
    
    			    seconds=59; 
    			    
    				if(cashmins!=-2) cashmins -=1;
    
    				if(healthmins!=-2) healthmins-=1;
    
    				if(energymins!=-2) energymins -=1;
    
    				if(strengthmins!=-2) strengthmins -=1;
    
    			 } 
    
    			 if (cashmins == -1) {
    
    			 	seconds = 0;
    
    			 	update = true;
    
    			 	cashmins += 1;
    
    			 }	
    
    			 if (healthmins == -1){ 
    
    			    seconds=0; 
    
    				update = true;
    
    			    healthmins+=1;
    
    				} 
    
    			if (energymins == -1){ 
    
    			    seconds=0; 
    
    				update = true;
    
    			    energymins+=1; 
    
    			} if (strengthmins == -1){ 
    
    			    seconds=0; 
    
    			    update = true;
    
    				strengthmins+=1; 
    
    			} 
    
    			 if(!update) 
    
    			 { 
    				display_loop_exsist = true;
    			    
    				seconds-=1;
    
    			    if(seconds<10) tseconds = "0"+seconds;
    
    				else tseconds = ""+seconds;
    
    				if(healthmins!=-2) healthtimer.setTextValue("More in: "+healthmins+":"+tseconds); else healthtimer.setTextValue("");
    
    				if(cashmins!=-2) cashtimer.setTextValue("More in: "+cashmins+":"+tseconds); else cashtimer.setTextValue("");
    
    				if(strengthmins!=-2) strengthtimer.setTextValue("More in: "+strengthmins+":"+tseconds); else strengthtimer.setTextValue(""); 
    
    				if(energymins!=-2) energytimer.setTextValue("More in: "+energymins+":"+tseconds); else energytimer.setTextValue("");  
    
    				setTimeout(function(){display(cashmins, healthmins, energymins, strengthmins, seconds, healthtimer, cashtimer, energytimer, strengthtimer)}, 1000); 
    
    			}else{
    
    				display_loop_exsist = false;
    				if(healthmins!=-2)healthtimer.setTextValue('');
    
    				if(cashmins!=-2)cashtimer.setTextValue('');
    
    				if(strengthmins!=-2)strengthtimer.setTextValue('');
    
    				if(energymins!=-2)energytimer.setTextValue('');
    
    				ajax.post('<?=$appcallbackurl?>aj_navi.php');
    
    			}
    
    	} 
    		display_loop_exsist = false;
    		
    		ajax = new Ajax();
    
    		ajax.responseType = Ajax.JSON;
    
    		ajax.ondone = function(data){
    			
    			var status = data.status;
    			if(status != "logged")
    			{
    				document.setLocation("<?php echo $appCanvasUrl; ?>");
    			}
     
    
    			cashmins=data.nextCashUpdateMins;
    
    			healthmins=data.nextHealthUpdateMins; 
    
    		 	energymins=data.nextEnergyUpdateMins; 
    
    		 	strengthmins=data.nextStrengthUpdateMins; 
    
    			seconds=data.nextUpdateSecs;
    			
    
    		
    			document.getElementById("goldc").setTextValue(data.ucash);	
    			document.getElementById("healthc").setTextValue(data.uhealth + '/' + data.umaxhealth);  
    			document.getElementById("energyc").setTextValue(data.uenergy + '/' + data.umaxenergy);  
    			document.getElementById("strengthc").setTextValue(data.ustrength + '/' + data.umaxstrength);
    			if (userexp != data.uexperience) {
    				document.getElementById("uexperiencec").setTextValue(data.uexperience + '/' + data.umaxexperience);
    				document.getElementById("expimagec").setSrc(data.expimage);
    				document.getElementById("ulevelc").setTextValue(data.ulevel);
    			}
    			userexp = data.uexperience;
    			
    			document.getElementById("armycounter").setTextValue(data.armycounter);
    			document.getElementById("pointscounter").setTextValue(data.pointscounter);
    			document.getElementById("statcounter").setTextValue(data.statcounter);
    			//document.getElementById("bountiescounter").setTextValue(data.bountiescounter);
    			
    
    			
    			if (!display_loop_exsist) {
    				if(data.to_make_timer_loop == 1)
    					display();
    			}
    		}
    
    		ajax.post('<?=$appcallbackurl?>aj_navi.php');
    		
    		function reload_counters()
    		{
    			ajax.post('<?=$appcallbackurl?>aj_navi.php');	
    		} 
    
    	</script>
    
    HTML:
    The aj_navi.php page returns the below and verified the data is being populated but not working in above ajax script

    
    	{
    	"status":"logged",
    	"to_make_timer_loop" : "<?php echo $to_make_timer_loop;?>",
    	"ulevel" : "<?php echo $row[ulevel];?>",
    	"uexperience" : "<?php echo number_format($row[uexperience],0);?>",
    	"umaxexperience" : "<?php echo number_format($absmax,0);?>",
    	"expimage" : "<?php echo $expimage;?>",
    	"uhealth":"<?php echo $row[uhealth]?>",
    	"umaxhealth":"<?php echo $row[umaxhealth]?>",
    	"uenergy":"<?php echo $row[uenergy]?>",
    	"umaxenergy":"<?php echo $row[umaxenergy]?>",
    	"ustrength":"<?php echo $row[ustrength]?>",
    	"umaxstrength":"<?php echo $row[umaxstrength]?>",
    	"armycounter":"<?php echo get_crew($user)?>",
    	"statcounter":"<?php echo get($user,'uskillpoint',true)?>",
    	"pointscounter":"<?php echo get_fav_point($user)?>",
    	"bountiescounter":"<?php echo '0'?>",
    	"ucash":"<?php echo number_format($row[ucash],0)?>",
    	"nextUpdateSecs":"<?php echo $nextUpdateSecs+2 ?>", 
    	"nextCashUpdateMins":"<?php echo $nextCashUpdateMins?>",
    	"nextHealthUpdateMins":"<?php echo $nextHealthUpdateMins?>",
    	"nextEnergyUpdateMins":"<?php echo $nextEnergyUpdateMins?>",
    	"nextStrengthUpdateMins":"<?php echo $nextStrengthUpdateMins?>"
    }
    
    HTML:

    and home.php file not working for links using ajax page loading.
    
    
    <script src="http://code.jquery.com/jquery-1.5.js"></script>
        <script type="text/javascript">
    		
    		function update_links()
    		{
    			var root =document.getElementById("body");
    		
    			var i=0;
    			var j=0;
    			
    			var links = root.getElementsByTagName("a");
    			var len = links.length;
    		    //var not_ajax = {"add_to_profile":1};
    			
    			while(i<len){
    				var hr = links[i].getHref();
    				
    				if (links[i].getId() == "add_to_profile") {
    					 i = i + 1;
    					continue;
    				}
    				if (links[i].getId() == "not_ajax") {
    					 i = i + 1;
    					continue;
    				}
    				
    				if (hr.indexOf("<?php echo $appCanvasUrl; ?>") == -1) {
    					i = i + 1;
    					continue;
    				}
    				
    				
    				links[i].purgeEventListeners('click');
    				links[i].addEventListener('click', function(e){
    					e.preventDefault();
    					var href = this.getHref();
    					href = href.split("/");
    					href = href[href.length - 1];
    					href = "<?php echo $appcallbackurl; ?>" + href;
    					
    					make_ajax_call(href, "", "middlebox");
    					return false;
    				}, false); 
    				i=i+1;
    			}
    		}
    		
    		function on_aj_error(url,container)
    		{
    			document.getElementById(container).setInnerXHTML("<div style='height:500px;'><span class=\"reload_link\" id=\"rl1\">Loading Error. Try to refresh</span></div>");
    			var rl1 = document.getElementById("rl1");
    			rl1.addEventListener('click',function(e){
    					make_ajax_call(url,'');
    				},false);	
    		}
    		
    		function make_ajax_call(url,query,container)
    		{ 
    			//!!!!!!!!!!!!!! only for debug
    			document.getElementById('debug').purgeEventListeners('click');
    			document.getElementById('debug').addEventListener('click', function(e){
    					e.preventDefault();
    					make_ajax_call(url, query, container);
    					return false;
    				}, false); 
    			//!!!!!!!!!!!!!!
    			
    			if(container == undefined || container==null) container = "middlebox"; 
    			document.getElementById(container).setInnerXHTML(
    				"<center><div style='height:500px;'><img src=\"<?php echo $appcallbackurl; ?>images/loader.gif\" />"
    				+ "<br /><span class=\"reload_link\" id=\"rl1\">Not Loading? Click here to refresh</span>"
    				+ "</div></center>"
    			);
    			var rl1 = document.getElementById("rl1");
    			rl1.addEventListener('click',function(e){
    					make_ajax_call(url,'');
    				},false);
    			
    			var ajax2 = new Ajax();
    			
    			ajax2.responseType = Ajax.FBML;
    			
    			ajax2.ondone = function(data){	
    				document.getElementById(container).setInnerFBML(data);
    				var aj_status = document.getElementById("aj_status");
    				if(aj_status!="undefined" && aj_status!=null)
    				{ 
    					aj_status = aj_status.getValue();
    					if (aj_status == "Error") on_aj_error(url,container);
    					else document.setLocation("<?php echo $appCanvasUrl; ?>");
    					return;
    				}
    			
    				update_links();
    				
    				var reload_status = document.getElementById("ajax_callback_request");
    				if (reload_status != "undefined" && reload_status != null) 
    				{
    					if(reload_status.getValue()=="refresh_counters")
    					reload_counters();
    				}	 
    			}
    			
    			ajax2.onerror = function(){
    				on_aj_error(url,container); 
    				update_links();
    			}
    			if (typeof(query) == 'object') {
    			
    				query.isajax = "true";
    			}
    			else {
    				query = {
    					"isajax": "true"
    				};
    			}
    			//ajax2.requireLogin = true;
    			ajax2.post(url,query);
    		}
    		update_links();
    		//make_ajax_call("<?php echo $appcallbackurl.$cont->page; ?>","","middlebox");
    
    		</script>
    
    
    HTML:
    Any help would be greatly appreciated and in return will rep, and +1 trader
    possible pay for fix..


    Paying $$-$$$ for fixes
    If you feel that is not enough feel free to tell me your price. This shouldn't be to bad considering all the code is there..

    Thank you in advance,
    TJ
     
    Last edited: Mar 17, 2011
    lowridertj, Mar 17, 2011 IP