我试图从php页面获取一个xml字符串,并在jQuery中更新一些节点值。但是,我无法弄清楚如何操作我在jquery中获取的XMLDocument,然后将其作为xml字符串返回到php页面。非常欢迎任何帮助。
var test = <?php echo json_encode($test_xml); ?>;
test = test.replace(/\r\n|\n|\r/g, ''); // <config><exclude_days_of_week>0</exclude_days_of_week><exclude_days_of_week>1</exclude_days_of_week></config>
var test_xml = $.parseXML(test);//some error "not well formed" but doesn't stop code from running
var exclude_days_of_week = $(test_xml).find("exclude_days_of_week").text().toArray(); // [0] [6]
然后保存,
$('#save_type').on('click', function() {
$(appointment_view_xml).find('exclude_days_of_week').remove(); // doesn't work
var new_exclude_days_of_week = $("#working_days_of_week li:not('.working_day')").map(function(i, v) {
$(appointment_view_xml).find('config').append('<exclude_days_of_week>' + v.value + '</exclude_days_of_week>');
return v.value;
}).get();
return $(appointment_view_xml); // doesn't work too
});