Everthing here works fine except that in the saved file it doesn\'t give me the whole string. Just one of the IDs (There are multiple on the page).
Not sure how get \"al
You forgot to enclosed the for
loop into {
and }
.
$('a#exportPage').on('click',function(){
var contentMap = {};
$('[id^="appendHeading"]').each(function(){
contentMap[this.id] = $(this).text();
});
for(id in contentMap) {
$("#PrintIds").append("ObjectID:" + id + "Content:" + contentMap[id]);
$.ajax({
url: "post.php",
type: "post",
data: {
objectID: id,
content: contentMap[id]
},
success: function(){
alert("success");
},
error:function(){
alert("failure");
}
});
}
});
The content should be appended to the end of the file:
<?php
if ($_POST['objectID'] || $_POST['content']) {
$myFile = "test.css";
$stringData = $_POST['objectID'] . ':' . $_POST['content'] . "\n";
file_put_contents($myFile,$stringData,FILE_APPEND | LOCK_EX);
}
?>