Jump to content
MakeWebGames

Add teh buttons


AnonymousUser

Recommended Posts

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 by AnonymousUser
Thank You Sniko =)
Link to comment
Share on other sites

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>

 

Edited by sniko
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

 

lol thank you sir! i'll be sure to get right on securing this code :) you're help is much appreciated

Link to comment
Share on other sites

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 by sniko
Link to comment
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.

×
×
  • Create New...