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

1

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.