Jump to content
Beffic

Jquery Select Tag Problem?

Recommended Posts

So I am trying to get this project done as soon as possible for my client. I am having problems with it and I do not understand.So I am here. To you lovely people! =)So I have an inventory when when ever you hit equip or unequip it will go through the JavaScript function and process the MySql query in a separate PHP file. And for some reason I get a delayed effect or a bugged effect to where it does not process or it takes forever to make the change/ delayed showing effect.Also in IE it will show the table of all my equipment but in FF it wont...I am using JQuery library file found at www.jquery.comindex.php

<tr><td>    <h3>Inventory</h3>    <div id="inventory"></div></td><td><script src="http://code.jquery.com/jquery-latest.js"></script><script>var refreshId = setInterval(function(){     $('#inventory').load('inventory.php').fadeIn("slow");}, 5000);</script> 

inventory.php

<?php      include("../../connect.php");if(!isset($_COOKIE['player_id']))  die('Please login.<br><a href=../../index.php>Go back</a>.');$Player=$_COOKIE['player_id'];$Query="SELECT * from Users where ID='$Player'";$Query2=mysql_query($Query) or die("Could not get user stats.");$User=mysql_fetch_array($Query2);if($_COOKIE['password'] !=md5($User['Password']))  die('Your Password doesnt seem right for this account. <a href=../../index.php>go back</a>');?><script type="text/javascript" src="jquery-1.3.2.min.js"></script><script src="http://code.jquery.com/jquery-latest.js"></script><script type=text/javascript>$(document).ready(function(){   $("form#UNEquip").submit(function() {    var id     = $('#id').attr('value');       $.ajax({         type: "POST",         url: "unequip.php",         data: "id="+ id,         success: function(){            $('div.success').fadeIn().fadeOut();         }      });   return false;   });});$(document).ready(function(){   $("form#Equip").submit(function() {    var id2     = $('#id2').attr('value');       $.ajax({         type: "POST",         url: "equip.php",         data: "id="+ id2,         success: function(){            $('div.success').fadeIn().fadeOut();         }      });   return false;   });});</script><table border=\"1px\"><tr><td><b><u>Equipped</u></b></td><td><b><u>Class</u></b></td><td><b><u>Action</u></b></td></tr><tr><?php  $start="SELECT * FROM `Inventory` WHERE Owner='$Player' AND Equipped='Yes'";  $start2=mysql_query($start);  print"<form id=\"UNEquip\" method=\"post\">";  while($Equipped=mysql_fetch_array($start2)){   $Class=mysql_fetch_array(mysql_query("SELECT Class FROM Items WHERE Name='".$Equipped['Name']."'"));   print"<td><i><input type=\"hidden\" id=\"id\" value=\"".$Equipped['ID']."\">".$Equipped['Name']."</i></td><td><i>".$Class['Class']."</i></td><td><input type=\"submit\" value=\"Unequip\"></td>";  }  print"</form>";?></tr><tr><td><b><u>Inventory</u></b></td><td><b><u>Class</u></b></td><td><b><u>Action</u></b></td></tr><tr><?php  $starter="SELECT * FROM `Inventory` WHERE Owner='$Player' AND Equipped='No'";  $starter2=mysql_query($starter);  print"<form id=\"Equip\" method=\"post\">";  while($UNEquipped=mysql_fetch_array($starter2)){  $Class=mysql_fetch_array(mysql_query("SELECT Class FROM Items WHERE Name='".$UNEquipped['Name']."'"));   print"<td><i><input type=\"hidden\" id=\"id2\" value=\"".$UNEquipped['ID']."\">".$UNEquipped['Name']."</i></td><td><i>".$Class['Class']."</i></td><td><input type=\"submit\" value=\"Equip\"></td>";  }  print"</form>";?></tr></table><div class="success" style="display:none;">Item changed!</div> 

equip.php

<?php        // where is your config file stored?   include ("../connect.php");    // CLIENT INFORMATION   $id        = htmlspecialchars(trim($_POST['id']));     $addClient  = "UPDATE `Inventory` SET Equipped='Yes' WHERE ID='$id'";    mysql_query($addClient) or die(mysql_error()); ?> 

unequip.php

<?php        // where is your config file stored?   include ("../connect.php");    // CLIENT INFORMATION   $id        = htmlspecialchars(trim($_POST['id']));     $addClient  = "UPDATE `Inventory` SET Equipped='No' WHERE ID='$id'";    mysql_query($addClient) or die(mysql_error()); ?>

I am new to this forum and I am glad to be a part of this new community. I have used w3 tutorials for all my years of scripting and have never been underestimated.Thanks for looking,Beffic

Share this post


Link to post
Share on other sites

You should use Firebug to help debug ajax stuff. Opera 10 also has a good developer console, and IE8 has a pretty decent one also. But if you're using Firefox, install the Firebug extension and enable it on your site. Once that's done, you can open the Firebug console and click on the Net tab to see the requests going out and coming back. When you run the ajax stuff you should see a new request pop up, and you can look at the request to figure out if it had any errors and also check the response text. Once you know what the response is, you can debug the Javascript to figure out why it's not doing what it should with the response text.

Share this post


Link to post
Share on other sites
You should use Firebug to help debug ajax stuff. Opera 10 also has a good developer console, and IE8 has a pretty decent one also. But if you're using Firefox, install the Firebug extension and enable it on your site. Once that's done, you can open the Firebug console and click on the Net tab to see the requests going out and coming back. When you run the ajax stuff you should see a new request pop up, and you can look at the request to figure out if it had any errors and also check the response text. Once you know what the response is, you can debug the Javascript to figure out why it's not doing what it should with the response text.
Ahh yes, Mr. Firebug. I have tried using this little guy before but I still cannot seem to get an error and I can't really test it in FF because it's not showing the items I have from the mysql query... Any help with that part. Cause everything looks fine on the query to me but if it was fine then it would display the items...

Share this post


Link to post
Share on other sites

Right, that's why you need to use Firebug to look at the request, you need to figure out the data that is being sent back from the query. When you look at the request, you can look at the response to figure out what the PHP script is sending back to Javascript. Once you know that you can figure out why the Javascript isn't using it correctly.

Share this post


Link to post
Share on other sites

Okay, so I figured out this isn't a JavaScript problem I think.... but for some reason I cannot get the data from the mysql to show up when I have JavaScript try and load the file but it works when I go to the file directly.Any idea why it would do this?This is the code that loads the content into a div.

var refreshId = setInterval(function(){     $('#inventory').load('inventory.php').fadeIn("slow");}, 5000);

Share this post


Link to post
Share on other sites

Have you figured out the data that inventory.php is returning to Javascript? Is the data in the format that jQuery is expecting?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...