GetSimple Support Forum

Full Version: Load ajax subpage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi. This code echo all subpage. How show only 10 subpage and another load after with ajax.
PHP Code:
function getSubMenu($page){ 

 
$children=getChildren($page); 

 foreach (
$children as $subpage){ 
    
$title=returnPageField($subpage,'title'); 
    
$url=returnPageField($subpage,'slug'); 
    echo 
'<a href="/'.$url.'.html"> '.$title.'</a>'
  }


How make php function which show subpage (number from ajax). For example ajax:
Code:
$.ajax({  
                    type: "POST",  
                    url: "",
                    context: this,
                    data: {
                              'num'       : '10'
                           },
                    success: function(data){
                      console.log(data);
                    },
                    error: function(data){
                      console.log('error' + data);
                    }
                });
Slice the array using the page number via query string
See array_slice
(2014-07-19, 13:08:57)shawn_a Wrote: [ -> ]Slice the array using the page number via query string
See array_slice
Thanks, i add this code in functions.php

PHP Code:
if($_POST['ajaxload']) {

    
$num $_POST['ajaxload'];    
    
$children=getChildren(news);
    
$sliced array_slice($children0$num);
    
    foreach (
$sliced as $subpage){
        
$title=returnPageField($subpage,'title');
        
$url=returnPageField($subpage,'slug');
        echo 
'<li><a href="/'.$url.'.html">'.$title.'</a></li>';
     }


Code:
$('body').on('click', '#load', function() {

    
    $.ajax({  
                    type: "POST",  
                    url: "/theme/news/functions.php",
                    context: this,
                    data: {
                           ajaxload : '10'
                    },
                    success: function(data) {
             console.log(data);
                        alert(data);
                    },
                    error: function(output){
                      alert(resp);
                    }
                });
        
});

But onclick error

Quote:<b>Fatal error</b>: Call to undefined function getChildren()
Confused
are you tying to run this outside of GS ?
pretty sure thats is indeed a function in core, you are trying to load it directly outside of GS just submit to index not functions.
(2014-07-20, 00:30:50)shawn_a Wrote: [ -> ]are you tying to run this outside of GS ?
pretty sure thats is indeed a function in core, you are trying to load it directly outside of GS just submit to index not functions.
This php code is in functions.php my theme of GetSimple.

Simple code work

PHP Code:
if($_POST['ajaxload']) {

    
$num $_POST['ajaxload'];    
    
$newnum $num*2;
        echo 
''.$newnum.'';


return 20.

But when i try
PHP Code:
if($_POST['ajaxload']) {

    
$num $_POST['ajaxload'];    
    
$children=getChildren(news);
    
$sliced array_slice($children0$num);
    
    foreach (
$sliced as $subpage){
        
$title=returnPageField($subpage,'title');
        
$url=returnPageField($subpage,'slug');
        echo 
'<li><a href="/'.$url.'.html">'.$title.'</a></li>';
    }



return [object Object] and POST /functions.php 500 (Internal Server Error)
you do not send forms to your functions you send them to your index.
functions is loaded in global scope automatically and your code will run.
You also want to wrap it in a function and call in your template somehow if you want to use core functions
(2014-07-20, 01:58:29)shawn_a Wrote: [ -> ]you do not send forms to your functions you send them to your index.
functions is loaded in global scope automatically and your code will run.
(2014-07-20, 02:39:42)shawn_a Wrote: [ -> ]You also want to wrap it in a function and call in your template somehow if you want to use core functions

I have bad english and knowledge of php Smile, I still don't understand why it doesn't work.

Could you write a working example code?
I make file ajax.php in my theme, global functions will be work when ajax call it? How i can do it work?