我試圖在我的javascript中加載數組。我需要以某種格式將這個數組發送給一個我將要調用的PHP腳本。在下面的例子中,gSelectedMeds
是我的數組。價值count
將告訴PHP腳本有多少meds
期望收到。我無法將數組中的數據轉換爲可以通過$ .ajax數據選項發送的格式。任何幫助將不勝感激!!試圖從jQuery發送一個數組到PHP函數
下面的代碼是給我的悲傷在此刻的部分是數據選項:
$('#export').click(function() {
$.ajax({
url:'ajax-exportMeds.php',
data:
{"number":gSelectedMeds.length},
$.each(gSelectedMeds,
function(intIndex, objValue){
{"med"+intIndex:objValue},
}
),
type: "GET",
//dataType: "text",
success: function(data){
$('p#allMeds').text('');
$('a.bank').text('');
//clear array, bank and storedList divs
$(this).text('');
gSelectedMeds[] = '';
//$('ul#storedList').fadeOut('fast');
$('ul#storedList').text('');
return false;
},
}),
});
@FilmJ建議http://stackoverflow.com/questions/838845/having-problem-getting-the-posted-array-from-jquery/1713985#1713985 – dsummersl 2014-05-04 14:26:09