[Help!]Help me...inventory onclick ajax!!

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
KimChunChu
Posts: 4
Joined: Mon Jan 02, 2012 9:03 pm

[Help!]Help me...inventory onclick ajax!!

Post by KimChunChu »

Hello!
I want to make an inventory simple click and display the image on the image data as it:


Image

but I saw the source code to this inventory with ajax function looks like this:

Code: Select all

<script language="javascript">
var flashboxid = "char_box";
var delayer = 0;
var SplitResult;
function updater(slot,secondary) {
	if (delayer == 0){
	delayer = 1;
	xmlhttp = new XMLHttpRequest();
	xmlhttp.open("GET", "inv_update.php?slot=" + slot + "&item=" + secondary,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			if ((xmlhttp.responseText == "female") || (xmlhttp.responseText == "male"))
				alert("This item can only be eqipped by a " + xmlhttp.responseText);
			else{
			SplitResult = xmlhttp.responseText.split("XXX");
			document.getElementById('stat_box').innerHTML=SplitResult[0];
			document.getElementById('hp_box').innerHTML=SplitResult[5];
			document.getElementById('weapon_box').innerHTML=SplitResult[1];
		  document.getElementById('inv_box').innerHTML=SplitResult[2];
		  eval(SplitResult[3]);
		  document.getElementById('hidden_box1').innerHTML=SplitResult[4];
		  }
		  delayer = 0;
		}
	}
	xmlhttp.send(null);
	}
}

var delayer2 = 0;
function statup(stat){
	if (delayer2 == 0){
	delayer2 = 1;
	xmlhttp2 = new XMLHttpRequest();
	xmlhttp2.open("GET", "statup.php?stat=" + stat,true);
	xmlhttp2.onreadystatechange=function() {
		if (xmlhttp2.readyState==4) {
			returned_stats = eval("(" + xmlhttp2.responseText + ")");
			
                  document.getElementById('health').innerHTML=returned_stats.health;
		document.getElementById('strength').innerHTML=returned_stats.strength;
		document.getElementById('agility').innerHTML=returned_stats.agility;
		  document.getElementById('precision').innerHTML=returned_stats.precision;
		  document.getElementById('defence').innerHTML=returned_stats.defence;
		  document.getElementById('mana').innerHTML=returned_stats.mana;

		  if (returned_stats.remaining == "")
                   {
		  	document.getElementById('remaining').innerHTML="";
		  	document.getElementById('health_b').style.display = "none";
		  	document.getElementById('strength_b').style.display = "none";
		  	document.getElementById('agility_b').style.display = "none";
		  	document.getElementById('precision_b').style.display = "none";
		  	document.getElementById('defence_b').style.display = "none";
		  }
		  else
                  {
		  	document.getElementById('remaining').innerHTML=returned_stats.remaining;
		  }
		  delayer2 = 0;
		}
	}
	xmlhttp2.send(null);
	}
}
</script>
I just want to be a simple one:
1. Inventory holding objects when the team by clicking to display the data object we just clicked and the character back in stock.
2. When the team to update objects and equipment items with attributes object in nature.


I want to help ... .. please. :oops: :( :cry:
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: [Help!]Help me...inventory onclick ajax!!

Post by Jackolantern »

I'm sorry, but I can't really understand what you are asking for.

However, one tip that always holds true for me, is that you should look into jQuery for Javascript, particularly for AJAX calls. jQuery makes AJAX ridiculously easy, and it also makes it much easier to fit AJAX into the logic of your game system, since it reduces AJAX into a single function call, rather than AJAX being a huge structure that you have to blend your application in to.
The indelible lord of tl;dr
KimChunChu
Posts: 4
Joined: Mon Jan 02, 2012 9:03 pm

Re: [Help!]Help me...inventory onclick ajax!!

Post by KimChunChu »

Ready!
I solved by a simple function XMLHttpRequest ajax.
Thanks in advance!
Post Reply

Return to “Advanced Help and Support”