checkdata['attendance_batch'] = [
{user_id_c: 'abcda', ispresent: 0},
{user_id_c: 'abxcda', ispresent: 2},
{user_id_c: 'abctda', ispresent: 1}
]
我希望我在上面提到的格式排列在javascript提交的二維陣列以JavaScript
MY HTML:
<label for='flip'>" + entry["name"] + "</label><div id='switch'><select name='user_id_c' id='flip2b' iduser='"+entry["id"]+"' data-role='slider'><option value='1'>Present</option><option value='0'>Absent</option></select>
$("#frmattendance").submit(function(event) {
event.preventDefault();
$form = $(this);
var a = {};
var paramString = [];
$($form).find(':input').each(function() {
//console.log($(this).attr('name'));
if ($(this).val() == 'Mark') {
}
else {
a[{user_id_c: $(this).attr('iduser'), ispresent: $(this).val()}];
// console.log(a[$(this).attr('name')]);
}
});
var $sessiondata = sessionStorage.sessionid;
$.ajax
({
type: "POST",
url: saverecordurl + 'pcc_attendance',
dataType: 'json',
async: false,
// session_id: $sessiondata,
//json object to sent to the authentication url
data: {checkdata: a, session_id: $sessiondata},
success: function(response) {
//console.log(response);
if (response.id !== null)
{
alert("You have successfully marked the attendance");
$.mobile.changePage("#eventdetails", {
transition: "slide",
reverse: true,
changeHash: true
});
}
},
error: function(result) {
$.mobile.changePage("#one", {
transition: "slide",
reverse: false,
changeHash: true
});
}
})
});
有人可以幫助我的格式是我犯了一個錯誤嗎?
什麼是HTML做什麼呢? – amphetamachine 2014-10-07 19:24:34
從html獲取數據並形成數組 – vini 2014-10-07 19:26:09
這是一個對象數組,而不是一個二維數組。我不太清楚你在問什麼。當你說你想「提交」這些數據時,你的意思是喜歡在POST嗎? – 2014-10-07 19:26:21