Jquery AJAX Save to file

前端 未结 1 1395
眼角桃花
眼角桃花 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:

    
    

    0 讨论(0)
提交回复
热议问题