我有一個JavaScript函數收集兩個數組,圖像路徑和標題。 我想用PHP的帖子在同一個頁面$ _ SERVER [ 'PHP_SELF']送,但我真的不知道從哪裏開始..發送jQuery數組到PHP post?
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; ?>">
AFAIK jQuery不支持。對於純JS解決方案,請參閱此問題:http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit – Tgr 2010-05-14 01:49:43