Jquery AJAX Save to file

前端 未结 1 1394
眼角桃花
眼角桃花 2021-01-25 23:01

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

相关标签:
1条回答
  • 2021-01-25 23:41

    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);
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题