We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20547
    • 6 Posts
    Hello all,
    I am trying to use a snippet to process a cell edit from TableKit. http://www.millstream.com.au/view/code/tablekit/
    I am stumped on how to reference a snippit from a javascript include like this.

    It seems to stop parsing at the ’=’ and loads the index page instead of the results from the aliased snippet. How do I escape the ’=’, or even better, how can I call the snippet directly instead of the page alias? Using the ID listed in MODx for the snippet doesn’t seem to work either since there are usually pages with the same ID
    <script type="text/javascript"><!--
         TableKit.options.editAjaxURI = 'index.php?page=edit_table';
    // --></script>
    


    Here is my snippet:
    <?php
    header('Content-Type: text/plain; charset=UTF-8');
    global $modx;
    
    $table = "modx_site_medialibrary";
    $id = $_POST['id']; 
    $value = $_POST['value'];
    $field = $_POST['field'];
    
    $rows_affected = $modx->db->update($field=$value, $table, id=$id);
    
    echo $value;
    ?>
    


    I have also tried putting the PHP in a stand alone file, but the UPDATE call doesn’t work...

    Thank you for any suggestions!
      • 22303 MODX Staff
      • 10,725 Posts
      Why wouldn’t you use a page to represent the Ajax call? Then you simply use that pages id to create the url, say if it was page with id 13:

      <script type="text/javascript">
           TableKit.options.editAjaxURI = '[~13~]';
      </script>


      I typically use a snippet to output the JS as well, then you could make the page id of the Ajax processor configurable in the snippet call.