javascript - Jquery POST sending multiple variables -


i've been trying figure out issue website while now--i have bunch of "stars" user can click on.

clicking on star loads file div information regarding star. loads button players click , "take over" planet. working , fine, however--i've discovered issue i'm not quite sure how handle.

if player clicks on multiple stars before reloading page whatever reason--when click attack/whatever star--it'll send multiple requests across server. @ first thought in coding sending information regarding stars, i've come realize it's stars player has clicked on.

now--here code:

$.ajaxsetup ({     // disable caching of ajax responses     cache: false });     function loadstatus() {         $.ajax(         {             url:'world1.php', error: function () { }, datatype:'json',             success: function(data)             {                 denial = false;                 $('#credits').html(data.credits);                 $('#fuelleft').html(data.fuel);                 $('#energyleft').html(data.energy);             }         });  } function currentstarmapurl(url) {         $('#starmap').load(url, {},         function()         {             $('#loader').hide();             fullstarinformation(url);             starinformation();             setinterval(function() { $('.unknown').effect("highlight",{color:"#800000"}, 1500)});             return false;            }         ); }  /*     purhcase upgrades */ /*     retriever better star info  */ function fullstarinformation() {     $(".star").click(         function()         {             $('#planet-bar').empty();             val = this.id;             url = "planet.php?sid="+val;             $('#planet-bar').load(url, {'sid':val},                 function()                 {                     colony(url);                 }             );         }         ); } function colony(url) {     $('#planet-bar').on("click", "button",     function() {         event.preventdefault();          name = 0;         $(this).hide();             name = $(this).attr('sid');             $.post('purchase.php?mode=planet', {sid: name},                  function ()                  {                      $('#planet-bar').load(url, {}, function () { currentstarmapurl(url2); })                 }                 );           $(this).prop('disabled', true);           });  } 

i figured @ first issue caching issue, added $.ajaxsetup first line, didn't seem change anything. figured, maybe it's way code being called--i had 2 seperate functions; 1 attack, 1 colonizing. both of being called in fullstarinformation function, moved down 1 function, i'm still getting issue.

afaik, right now, may have rewrite entire block of code colony function , starinformation function separate , not acting upon 1 another. wanted second, third maybe fourth set of eyes on code before go doing that.

if getting multiple ajax calls, chances setting multiple event handlers. glancing through code, think should change

function colony(url) {   $('#planet-bar').on("click", "button", function() { ... } ); 

to

function colony(url) {   $('#planet-bar').off("click", "button"); //unbind old event handlers   $('#planet-bar').on("click", "button", function() { ... } ); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -