jQuery .load() passing array and retrieving it with php

Discussion in 'Web Design and Development' started by seventeen, Apr 28, 2009.

  1. seventeen macrumors member

    Joined:
    Apr 9, 2009
    Location:
    Denton, Tx
    #1
    so i am messing around with jquery's .load(). I'm sending an array of parameters to a php script to be executed like so:

    Code:
    $(document).ready(function() {
    	$('#result').load('test.php', { 'params[]': ["<?php echo $params[0]; ?>", "<?php echo $params[1]; ?>"] });
    });
    the problem is, how to i retrieve this 'param' array within my php script? is it sending a post request, so could i get it like $_POST['param'] or something?

    thanks
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    You'll want to send parameter pairs, just like you see in a GET method:
    Code:
    ["param1=something", "param2=otheritem"]
    Then in PHP like you would guess,
    PHP:
    $param1 $_POST['param1'];
    $param2 $_POST['param2'];
    I was recently working on some AJAX and ran into the same question.
     
  3. seventeen thread starter macrumors member

    Joined:
    Apr 9, 2009
    Location:
    Denton, Tx
    #3
    Thanks, while I was waiting for your reply yesterday I went ahead and just set it up to work without the array in much the same way as you suggested.

    But I've run into another problem. It appears none of the while and/or for loops in the php script are executing...

    I threw in some 'debugging' echos to see where I was losing my variable values. and yeah, it looks like my loops are just being totally ignored.

    Any idea on why something like this might be happening?
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    Can you post some code?
     

Share This Page