Send jQuery array to PHP post?

Posted by FFish on Stack Overflow See other posts from Stack Overflow or by FFish
Published on 2010-05-13T23:54:21Z Indexed on 2010/05/14 1:24 UTC
Read the original article Hit count: 350

Filed under:
|
|
|
|

I have a javascript function that gathers two arrays, imagepaths and captions. I want to send with PHP's post to the same page $_SERVER['PHP_SELF'], but I really don't know where to start..

PHP:

if (isset($_POST['Submit'])) {
    $edit_photos->update_xml($edit_photos->album_id, $_POST['src_arr'], $_POST['caption_arr']);
    // prevent resending data
    header("Location: " . $_SERVER['PHP_SELF'] . "?ref=" . $ref);
}

JS:

function getImgData() {
    var imgData = { 'src_arr': [], 'caption_arr': []};
    $('.album img').each(function(index){
        imgData.src_arr.push($(this).attr('src'));
        imgData.caption_arr.push($(this).attr('alt'));
    });
    return imgData;
};

HTML:

<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?ref=" . $ref; ?>">

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery