javaScript error in handleHashChange() function

Discuss MySQL Ajax Table Editor

javaScript error in handleHashChange() function

Postby Atara » Thu Feb 15, 2018 2:58 pm

I try to use two TABLEs on the same page, base on the sample code.

but in my case I get the following JavaScript error:
Code: Select all
TypeError: data is undefined  ajax_table_editor.js:262:4
handleHashChange http://mySite.com/mate/js/ajax_table_editor.js:262:4
addPopState/<    http://mySite.com/mate/js/ajax_table_editor.js:271:5
init             http://mySite.com/mate/js/ajax_table_editor.js:118:7
<anonymous>      http://mySite.com/mate/myFile.php:113:5



the relevant PHP in my file is -
Code: Select all
...
   protected $mateInstances = array('mate_cardTags_', 'mate_cardImgs_');
...
   
   $defaultSessionData1['orderByColumn'] = 'map_id';
   // $defaultSessionData1 = base64_encode($this->Editor->jsonEncode($defaultSessionData1)); // no Editor!
   $defaultSessionData1 = base64_encode(json_encode($defaultSessionData1));
   
   $defaultSessionData2['orderByColumn'] = 'ci_position';
   $defaultSessionData2 = base64_encode(json_encode($defaultSessionData2));
...
   $javascript = '   
      <script type="text/javascript">
         var ' . $this->mateInstances[0] . ' = new mate("' . $this->mateInstances[0] . '");
         ' . $this->mateInstances[0] . '.setAjaxInfo({url: "cfg_card_tags.php?cid=' . $_GET["cid"] . '&xx=55", history: true});
         ' . $this->mateInstances[0] . '.init("' . $defaultSessionData . '");
   ';
   $javascript .= '
         var ' . $this->mateInstances[1] . ' = new mate("' . $this->mateInstances[1] . '");
         ' . $this->mateInstances[1] . '.setAjaxInfo({url: "cfg_card_imgs.php?cid=' . $_GET["cid"] . '", history: true});
         ' . $this->mateInstances[1] . '.init("' . $defaultSessionData . '");
   ';

   $javascript .= '
      </script>';



it turns into -
Code: Select all
   var mate_cardTags_ = new mate("mate_cardTags_");
   mate_cardTags_.setAjaxInfo({url: "cfg_card_tags.php?cid=101&xx=55", history: true});
   mate_cardTags_.init("eyJvcmRlckJ5Q29sdW1uIjoibWFwX2lkIn0=");
   
   var mate_cardImgs_ = new mate("mate_cardImgs_");
   mate_cardImgs_.setAjaxInfo({url: "cfg_card_imgs.php?cid=101", history: true});
   mate_cardImgs_.init("eyJvcmRlckJ5Q29sdW1uIjoiY2lfcG9zaXRpb24ifQ==");


in cfg_card_tags.php, I use
Code: Select all
   protected $instanceName = 'mate_cardTags_';

in cfg_card_imgs.php, I use
Code: Select all
   protected $instanceName = 'mate_cardImgs_';



I tried to use the same $defaultSessionData for all pages -
Code: Select all
 
      $defaultSessionData['displayNum'] = 50;
      $defaultSessionData = base64_encode(json_encode($defaultSessionData));

but it also failed with the same error.


any hint why mateHashes does not contain the correct data, thus the following line fails -
Code: Select all
   var data = mateHashes[instanceName];



EDIT: after long debugging process, it looks like mateHashes array is changed, in init(), somewhere between
Code: Select all
  var forwardUrl = window.location.href.substr(0, window.location.href.indexOf('#'));
  window.location.href = forwardUrl + '#' + storedHash;


and the automate(?) call to the function
Code: Select all
handleHashChange()
Atara
 
Posts: 12
Joined: Wed Jul 26, 2017 9:01 am

Return to Open Discussion

Who is online

Users browsing this forum: Google [Bot] and 6 guests

cron