1

I'm using ajax to make a pager. I'm passing the "pag" variable through the url page.

//Initialise the table at the first run
$( '#content' ).load( "paginator.php?pag=1", function() 
{
    hide_anim();
});

//Page navigation Click
$( document ).on( 'click', 'li.goto',  function() 
{
    //Get the id of clicked li
    var pageNum = $(this ).attr('id');
    //Loading Data
    $( "#content" ).load( "paginator.php?pag=" + pageNum, function() 
    {
        hide_anim();
    });
});

Now I'd like to pass also a variable that contains an array. You can do it?

My array

$src = array (’name’ => ‘foo’, ‘sname’ => ‘’, age => '22');

Otherwise I could do the same thing (load) using post? How could I do that? Thanks

EDIT

I did it this way.

//Loading Data
$( "#content" ).load( "paginator.php", { pag: pageNum, phparr=?? }, function() 
{
    hide_anim();
});

Now, how can I get the array from php and pass it as a jquery variable (phparr) ? Thanks

Paolo Rossi
  • 2,490
  • 9
  • 43
  • 70
  • Have a look at JSON Stringify and use an object rather than an array. Then decode the JSON on the serverside. http://stackoverflow.com/questions/16196338/json-stringify-doesnt-work-with-normal-javascript-array – Rob Schmuecker May 06 '14 at 07:26

2 Answers2

1

use $ajax as

$.ajax({
          url  : 'paginator.php',
          type : 'POST',
          data : {pag="+<?php echo $src?>},
          success:function(result){
                hide_anim();
          }
      });

in the paginator get $_POST['pag'], and treat it as array I haven't actually tried it, but it should work Hoping for best

0

You can use $.post() instead $.load()

http://api.jquery.com/jquery.post/

EDIT

to replace PHP array to JSON object use:

 var arr = <?php json_encode($arr); ?>

and all together:

$( "#content" ).load( "paginator.php", { pag: pageNum, data:arr }, function() 
{
    hide_anim();
});
cieszynka
  • 91
  • 3