We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38189
    • 31 Posts
    Quote from: markodey at Jul 10, 2013, 12:49 AM
    you can use isset($varname) or

    $varname=$modx->getOption('varname',$scriptProperties,'value');

    the first one is only php the second on ensure that if it has no value it will create one with the desired value

    The first option gave me the same error, second option did no error, but got nothing rendered besides the outline of the div.
      • 40762
      • 54 Posts
      first off , I have a feeling you are not passing your argument right. The reason you got your first error was mostlikely because of that.

      I remember struggling to implement this codes. I wanted to do a gallery with ajax. you should maybe consider not using this. getPage is very slow I find espacially if you load tvs. I would sometime get 15s of waiting time for uncached elements.

      I think the best practise would be to program it without ajax and then create a javascript program that would take care of loading the page and filter it to keep only what it needs. I actually need to program something similar soon so I might post my strategy
        Marc-Andre Audet
        • 38189
        • 31 Posts
        Quote from: markodey at Jul 10, 2013, 05:27 AM
        first off , I have a feeling you are not passing your argument right. The reason you got your first error was mostlikely because of that.

        I remember struggling to implement this codes. I wanted to do a gallery with ajax. you should maybe consider not using this. getPage is very slow I find espacially if you load tvs. I would sometime get 15s of waiting time for uncached elements.

        I think the best practise would be to program it without ajax and then create a javascript program that would take care of loading the page and filter it to keep only what it needs. I actually need to program something similar soon so I might post my strategy

        I need ajax. I just don't get why this code doesn't work off the bat as describe in the post earlier. Everyone seems to not have a problem implementing it but I guess my version hates me. I am just going to have to figure out how to work getPage at php level and make my own snippet but I don't know how long I am going to take because I quite frankly don't get in my mind the logic of using getPage and making an ajax request. I can do normal ajax request with getResources but getPage just baffles me. Thanks for the help though.
          • 38189
          • 31 Posts
          Well I figured one of the problems, snippet version points to an older version of mootools, so updated to proper one, now it displays but still get the ajax error. Gonna read more into it see if I can figure how to work.
            • 4172
            • 5,888 Posts
            will try to put a package together with the jquery-version
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 4172
              • 5,888 Posts
              here is a package, which should work.
              didn't try to install this package, yet.

              Test-example here: http://www.revo222.webcmsolutions.de/75/ajaxgetpage.html

              couldn't remove the first upload, use the second one

              [ed. note: Bruno17 last edited this post 10 years, 8 months ago.]
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 42082
                • 72 Posts
                Hey Bruno thanks for this great tutorial I was wounder has there been any success with this new plugin of yours? And If you have got it working could you please do a tutorial on it because i for the life of me cannot get it to work.

                Thanks,
                Modxnooby
                  • 42082
                  • 72 Posts
                  Hey Bruno thanks for this great tutorial I was wounder has there been any success with this new plugin of yours? And If you have got it working could you please do a tutorial on it because i for the life of me cannot get it to work.

                  Thanks,
                  Modxnooby
                    • 38189
                    • 31 Posts
                    Quote from: Bruno17 at Jul 19, 2013, 07:23 AM
                    here is a package, which should work.
                    didn't try to install this package, yet.

                    Test-example here: http://www.revo222.webcmsolutions.de/75/ajaxgetpage.html

                    couldn't remove the first upload, use the second one


                    Thank you Bruno. Will try it out.
                      • 44195
                      • 293 Posts
                      I too am having some trouble getting this to work.
                      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! smiley
                        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