DangerBoy Posted January 13, 2013 Share Posted January 13, 2013 Hi, I joined a game called http://www.eternalmafia.com and on some of the pages they load when you do an action (like busing someone from The Prison or committing a Crimes) without the browser reloading. How can I do this? Thank you Quote Link to comment Share on other sites More sharing options...
Someone Posted January 13, 2013 Share Posted January 13, 2013 http://api.jquery.com/jQuery.ajax/ Quote Link to comment Share on other sites More sharing options...
DangerBoy Posted January 13, 2013 Author Share Posted January 13, 2013 But how can I do it like they do it. So it does it with jQuery but then displays the result. Like on their The Prison page. Thank you for your help Quote Link to comment Share on other sites More sharing options...
Someone Posted January 13, 2013 Share Posted January 13, 2013 I am not gonna register there, so I only speak in general. yourjail.php should echo the message in html that you want to show $('#bust').click(function(){ $('#bustMsg').load("yourjail.php?bust=bustid"); }) <button id="bust">Bust from jail</button> <div id="bustMsg"></div> Quote Link to comment Share on other sites More sharing options...
DangerBoy Posted January 13, 2013 Author Share Posted January 13, 2013 Their code is: <script type="text/javascript"> $(document).ready(function(){ $(".bust").live('click', function() { $(this).html('Loading...'); $.ajax({ type: "POST", url: "../php/prison.php", data: "bust=" + $(this).attr('id'), success: function(response){ $('#content').html(response); $('#refresh').load("prisonfeed.php"); } });}); }); </script> But I don't understand it. Sorry, im new to javascript Quote Link to comment Share on other sites More sharing options...
Someone Posted January 13, 2013 Share Posted January 13, 2013 Have the link or button, or what else, the user clicks to bust out, have class named bust <a class="bust" id="#THENUMBERYOUUSUALLYPLACEINTHEBUSTURLDONTMEANTOYELLJUSTHIGHLIGHTING#" href="#">Bust</a> <div id="content">the busting result will be here</div> <div id="refresh"> this is probalby where the list of inmates is shown </div> I assume you have a jail and jailbusting script already, that may be soemthing like jail.php?bust=1234 url: "../php/prison.php", ^ change that to match the location of that script, have script look for $_POST['bust'] (remember to validate), and then do the busting, echo the result, and die; Whatever is echoed here should show up in the content div. Same principle with prisonfeed.php Quote Link to comment Share on other sites More sharing options...
DangerBoy Posted January 13, 2013 Author Share Posted January 13, 2013 Am I allowed to copy their javascript stuff? or should i write it again. :S Quote Link to comment Share on other sites More sharing options...
Someone Posted January 13, 2013 Share Posted January 13, 2013 You might learn more by writing it again. But I would not really call it copyright infringement to use the snippet. Perhaps use type: "GET", As according to guy expert on interfaces, POST causes two http calls to be made, and should be avoided unless sending much data. If you do that, make sure that the php backend script dont already use $_GET['bust'], if it does use $_GET['bust'] Change data: "bust=" + $(this).attr('id'), to data: "bustid=" + $(this).attr('id'), and look for $_GET['bustid'] in the php script. or something Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.