如何使用JSON发送多个值以便像这样拾取?我如何将此更改为JSON?
foreach($_POST['listItem'] as $key => $values){
list($eventDate, $eventTitle) = $values;
}
目前的值发送如下。但是这似乎不能正常工作,因为它只发送一些字符串。我也无法弄清楚在哪里/如何发送标题值。
这让我发疯。任何帮助都会很棒。
var txt = $("#listbox");
var caltitle = copiedEventObject.title
var dtstart = $.fullCalendar.formatDate(copiedEventObject.start, 'yyyyMMdd');
var txt = $('#listbox');
txt.append("<li class ='listItem'> " + dtstart + "</li>")
// remove the element from the "Draggable Events" list
$(this).remove();
}
});
$('#calendarform').submit(function(e) {
var form = $(this);
var listItems = $('.listItem');
listItems.each(function(index){ //For each event do this:
var listItem = $(this);
$("<input type='hidden'/>").val(listItem.text()).appendTo(form).attr('name', 'listItem[' + index + ']');
});
//Get text information from elements
});
编辑:
(使用JSON)
$('#calendarform').submit(function(e) {
var form = $(this);
var going_to_be_json = [];
list.each(function(i, item) {
going_to_be_json.push({
'id':'test',
'title': 'test'
});
});
$('#stuff').val(JSON.stringify(going_to_be_json));
});
foreach中的$ values变量是什么样的?它是一个数组还是一个字符串? jQuery代码应该帮助我们什么? – shadyyx
嗯,即时尝试制作一个数组。基本上我有一个日期和标题,我需要进入操作页面的foreach。我需要修改隐藏的输入来让它们都穿过,而我无法解决它。 –
不需要在''.attr('name','listItem []');''中使用''index''变量。像这样尝试。 – Valour