AnonymousUser Posted August 15, 2014 Posted August 15, 2014 (edited) Here's my ajax caller for my gym all i need is the buttons made for some reason i seem to having some technical errors lol or its getting late and i can't seem to think at the moment :D (Future Thanks & Thumbs Up) ***removed code due to completion of request Edited August 15, 2014 by AnonymousUser Thank You Sniko =) Quote
sniko Posted August 15, 2014 Posted August 15, 2014 (edited) Here's my ajax caller for my gym all i need is the buttons made for some reason i seem to having some technical errors lol or its getting late and i can't seem to think at the moment :D (Future Thanks & Thumbs Up) Considering you're switching on a _GET to call the respective function, this should suffice; (I've only done one button, but you'll get the gist on how to do the others. You will also need the jQuery library) <div id="response"></div> <a href="" class="trainButton" data-type="train" data-stat="strength">Train Strength</a> <script> $(document).ready(function() { $('.trainButton').click(function() { var strType = $(this).data('type'); var strStat = $(this).data('stat'); $.get('ajaxListener.php?cmd=' + strType + '&stat=' + strStat, function(strTrainResponse) { $('#response').html(strTrainResponse); }); }); }); </script> You're also open to SQL injection. <font> should not be used. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/font This looks more like your AJAX listener, not caller. Don't use exit; directly. At least call $h->endpage() beforehand. There is no default case handler Edited August 15, 2014 by sniko Quote
AnonymousUser Posted August 15, 2014 Author Posted August 15, 2014 Considering you're switching on a _GET to call the respective function, this should suffice; (I've only done one button, but you'll get the gist on how to do the others. You will also need the jQuery library) <div id="response"></div> <a href="" class="trainButton" data-type="train" data-stat="strength">Train Strength</a> <script> $(document).ready(function() { $('.trainButton').click(function() { var strType = $(this).data('type'); var strStat = $(this).data('stat'); $.get('ajaxListener.php?cmd=' + strType + '&stat=' + strStat, function(strTrainResponse) { $('#response').html(strTrainResponse); }); }); }); </script> You're also open to SQL injection. thank you a bunch bro you're a lifesaver :D Quote
AnonymousUser Posted August 15, 2014 Author Posted August 15, 2014 Considering you're switching on a _GET to call the respective function, this should suffice; (I've only done one button, but you'll get the gist on how to do the others. You will also need the jQuery library) <div id="response"></div> <a href="" class="trainButton" data-type="train" data-stat="strength">Train Strength</a> <script> $(document).ready(function() { $('.trainButton').click(function() { var strType = $(this).data('type'); var strStat = $(this).data('stat'); $.get('ajaxListener.php?cmd=' + strType + '&stat=' + strStat, function(strTrainResponse) { $('#response').html(strTrainResponse); }); }); }); </script> You're also open to SQL injection. <font> should not be used. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/font This looks more like your AJAX listener, not caller. Don't use exit; directly. At least call $h->endpage() beforehand. There is no default case handler lol thank you sir! i'll be sure to get right on securing this code :) you're help is much appreciated Quote
AnonymousUser Posted August 15, 2014 Author Posted August 15, 2014 i think you did the refill function for this code actually... Quote
sniko Posted August 15, 2014 Posted August 15, 2014 (edited) i think you did the refill function for this code actually... Nope. Unless with your implementation it changed. My code would send a HTTP GET request to ajaxListener.php?cmd=train&stat=strength. Your AJAX listener would "route" that request on switching the _GET['cmd'] value, down to the train() function. Admittedly, this should really be a POST. Create = PUT Retrieve = GET Update = POST Delete = DELETE ... POST if you are sending a command to the server to create a subordinate of the specified resource, using some server-side algorithm. Edited August 15, 2014 by sniko Quote
AnonymousUser Posted August 15, 2014 Author Posted August 15, 2014 cool thank you for explaining it to me i'm still learning on my ajax :D and as far as the codes go it's very old codes and needs to be updated so thank you for reminding me to sanitize and take the necessary precautions for this code to be added on :) Quote
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.