GetSimple Support Forum
QUESTION Load ajax subpage - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16)
+--- Thread: QUESTION Load ajax subpage (/showthread.php?tid=6580)



Load ajax subpage - werty1001 - 2014-07-19

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);
                    }
                });



RE: Load ajax subpage - shawn_a - 2014-07-19

Slice the array using the page number via query string
See array_slice


RE: Load ajax subpage - werty1001 - 2014-07-19

(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


RE: Load ajax subpage - shawn_a - 2014-07-20

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.


RE: Load ajax subpage - werty1001 - 2014-07-20

(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)


RE: Load ajax subpage - shawn_a - 2014-07-20

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.


RE: Load ajax subpage - shawn_a - 2014-07-20

You also want to wrap it in a function and call in your template somehow if you want to use core functions


RE: Load ajax subpage - werty1001 - 2014-07-20

(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?


RE: Load ajax subpage - werty1001 - 2014-07-27

I make file ajax.php in my theme, global functions will be work when ajax call it? How i can do it work?