We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44195
    • 293 Posts
    I originally posted this in http://forums.modx.com/thread/26847/pagination-without-refreshing-the-page?page=4#dis-post-494412
    but then realised that post had been archived so I'm re-posting here. The jQuery component I'm referring to can be found in the above link.



    I've got getPage working no problem with my custom snippet but I'm getting a 404 error when attempting to use Bruno's jQuery component above.
    From Firebug: "NetworkError: 404 Not Found - http://localhost/modx/index.php?id=3?id=3&items=10&current=1"

    My custom snippet (working perfectly when not using ajax):

    <?php
    $myComponent = $modx->getService('myComponent','MyComponent',$modx->getOption('mycomponent.core_path',null,$modx->getOption('core_path').'components/mycomponent/').'model/mycomponent/',$scriptProperties);
    if (!($myComponent instanceof MyComponent)) return 'Unable to load the voting system!';
      
    $competitionId = 9; // hardcoded this for now
    // Get total number of records
    $c = $modx->newQuery('items');
    if(!empty($competitionId)) {
        $c->where(array(
            'competition_id' => $competitionId
        ));
    }
     
    $total = $modx->getCount('items',$c);
     
    /* setup default properties */
    $limit = $modx->getOption('limit',$scriptProperties,6);
    $offset = $modx->getOption('offset',$scriptProperties,0);
    $sort = $modx->getOption('sort',$scriptProperties,'id');
    $dir = $modx->getOption('dir',$scriptProperties,'asc');
    $totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
    $modx->setPlaceholder($totalVar,$total);
     
    $c->limit($limit,$offset);
    $c->sortby($sort,$dir);
    $artworks = $modx->getCollection('items',$c);
     
    /* iterate */
    $output = '';
    foreach ($artworks as $artwork) {
        $artworkArray = $artwork->toArray();
        $output .= $myComponent->getChunk($tpl,$artworkArray);
    }
    return $output;
    


    My "home" resource:

    [[!ajaxGetPage? &ajaxpage=`3`]]
    <!-- Begin Pagination code -->
        <div id="pagination_controls">
            <div id="pagination_control_wrapper">
            </div>
            </div>  
        <div id="pagination_container">
           <div id="pagination_content_wrapper">
           </div>
        </div>
    <!-- End Pagination code -->
    


    My ajax resource with an id of 3 and a blank template:
    [[!ajaxGetPage?
    &ajax=`1`
    &sortBy=`id`
       &elementClass=`modSnippet`
        &element=`mycustomsnippet`
        &tpl=`myRowTpl`
        &totalVar=`total`
        &limit=`2`
    ]]
    


    and here is the template I'm using "myRowTpl"
    <li>
        <table>
            <tr><th>[[+name]]</th></tr>
            <tr><td>[[+description]]</td></tr>
            <tr><td><a href="/modx/assets/components/mycomponent/competitions/[[+competition_id]]/[[+filename]]"><img src="/modx/assets/components/mycomponent/competitions/[[+competition_id]]/thumbnails/[[+filename]]_medium.jpeg"></a></td></tr>
            <tr><td><a href="">Vote!</a></td></tr>
        </table>
    </li>
    


    If there's anything obvious that I'm missing, please let me know!

    This question has been answered by muzzstick. See the first response.

      I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
      Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com
    • discuss.answer
      • 44195
      • 293 Posts
      OK I realised I didn't have friendly URLs on so I've changed that and now I'm no longer getting a 404 error. I'm just not receiving any HTML back.

      http://localhost/modx/ajax-processor.html?id=3&items=10¤t=1 302 Found 2ms



      EDIT:

      Error log shows I'm getting an undefined ajax variable:
      (WARN @ C:\xampp\htdocs\modx\core\cache\includes\elements\modsnippet\42.include.cache.php : 9) PHP notice: Undefined variable: ajax


      RESOLUTION:

      *Facepalm* It was just a pathing problem! All good now. What a waste of time lol [ed. note: muzzstick last edited this post 10 years ago.]
        I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
        Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com
        • 4172
        • 5,888 Posts
        try to set your system-setting debug to 0
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 44195
          • 293 Posts
          Cheers Bruno, it seems I worked out what I was doing wrongly just as you posted that wink
            I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
            Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com