我有此陣列稱爲的SendData,其具有索引的SendData [0] [1] [2] .....如何通過AJAX後發送數據,使用數組
現在sendData[0]="name="+variable+"&class="+variable;
sendData[1]="name="+variable+"&class="+variable;
sendData[2]="name="+variable+"&class="+variable;
現在我該如何發送整個sendData?
我有此陣列稱爲的SendData,其具有索引的SendData [0] [1] [2] .....如何通過AJAX後發送數據,使用數組
現在sendData[0]="name="+variable+"&class="+variable;
sendData[1]="name="+variable+"&class="+variable;
sendData[2]="name="+variable+"&class="+variable;
現在我該如何發送整個sendData?
如果jQuery是允許的,那麼你可以嘗試以下方法:
$.ajax({
url:"Your URL",
type: "post",
data: {'data' : JSON.stringify(sendData)},
success: function (response) {
console.log(response);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
哦,沒有工作的所有...對不起...我發佈的代碼工作... thnxxxxxxx很多.... –
var sendData=new Object();
for(i=0;i<numberOfRows;i++){ //Number of rows
sendData[i]=new Object;
for(var key in return_data_columns_detail[0]){ //contains the json data for column headers
var id="ip"+cnt+"addRow"+addIpRow; //HTML ID for input fields contained inside table rows
var data=document.getElementById(id).value;
sendData[i][return_data_columns_detail[0][key]]=data;
cnt++;
}
addIpRow++
}
$.ajax({
url:"../include/handle_event_add_team.php",
type:"POST",
data:sendData,
dataType:"json",
success:function(){
console.log("after add button click team");
ajax_post_display_table();
//display_table_team();
}
});
ok here is how i did it by creating an object which can me parsed into json data and sending to php server
我試圖幫助你。你可以使用JQuery,你的html表單現在看起來像什麼? –