July 22, 201115 yr Hey, I'm not sure if this is possible, but if it is, could someone help me as it would save me lots of time. I have 2 spans on a page: Team Fortress 2 Counter Strike: Source Basically when one of these is clicked, I want a variable to be updated so I can use it in a mySQL query. Now obviously the php has already been run, which is why I have my doubts to whether this will work. Then I remembered about ajax, but I suck at it. So basically: Team Fortress 2 is clicked > Ajax request is sent > variable $server is updates with tf2. Without the page reloading. http://api.jquery.com/jQuery.post/ Thats where I got it from, but i'm pretty bad with Javascript If anyone could help, that;d be awesome.
July 22, 201115 yr I think you want to do something like this... Basically the onclick of team fortess 2 element sends an ajax "post" then I'm assuming you are returning the data/html that needs to be updated on the page from with in the php file? $("#idofdiv").click(function(){ $.post("/phpfilename.php",{postvariablename:'datato be sent'},function(responseText){ $("#idofdivtobeupdated").html(responseText); } });
July 22, 201115 yr Author Ah okay that makes more sense... But what would go in the: phpfilename.php file? Because I want the page to not reload, but still have the div updated. So what would that file have to contain?
July 22, 201115 yr phpfilename.php is the file that will be doing the mysql work etc. The page wont be updated the ajax simply sends a call to the php page and the server does the php work and normally you would return a response back to the javascript using a php "return". The javascript can then magically update the page without a refresh
Create an account or sign in to comment