dongzen7263 2014-10-02 15:33
浏览 45

使用AJAX和PHP永久存储注释[关闭]

I have written a POST and GET function in javascript to send comments from input and to retrieve stored comments whenever the page is loaded. However I don't know how to handle the data that I send, how do I handle it after the data is sent to save it and then on a later point be able to access it again after a reload? So in short, send comments to server, then retrieve them on a new pageload.

I was thinking of making a storage.php file where I would handle the data and then put it to a file, but i'm not quite sure how it would work.

Here are the POST and GET functions:

  self.getEntries=function(){
        $.ajax({
            type:"GET",
            url:"storage.php",
            dataType:'json',
            data: jsonData,
            success: function(data){
                    vm.comments=data.comments;
             }
        });
    }

 self.sendEntry=function(){
        $.ajax({
            type:"POST",
            url:"storage.php",
            dataType:'json',
            data: jsonData
        });
var jsonData=ko.toJSON(ViewModel);

Any help or examples would be very helpful! Thanks in advance. :)

  • 写回答

1条回答 默认 最新

  • douyonglang4845 2014-10-02 16:25
    关注

    Yes, you would want to create a PHP handler script that will take the data passed to it from your comments page, clean it up, and stick it into a database.

    Then, you would create another script that fetches the data from the database and echos it back to the comments page.

    I tend to see examples where people serialize the data inside of the AJAX calls before passing it to the PHP script.

    评论

报告相同问题?