简体   繁体   English

如何使用set和$ http.post保存在AngularJS中

[英]How to save in AngularJS using set and $http.post

I have a website that takes API from Django and retrieves the data and visualizes in HTML. 我有一个网站,该网站从Django获取API,并检索数据并以HTML形式进行可视化。 Now I want to save it each time I enter a website, so even if I refresh the page or close the server it won't disappear, but will be introduced to the table. 现在,我想每次进入网站时都保存它,因此即使刷新页面或关闭服务器,它也不会消失,但会被引入表格中。

This is my code for using the API to retrieve data: 这是我使用API​​检索数据的代码:

angular
    .module('inspinia')
    .controller('ListWebsiteCtrl', ['$scope', '$http', function ($scope, $http) {
        $scope.set = function (new_url) {
            $scope.data = new_url;
            $http.post("http://127.0.0.1:8000/api/website/" + this.get_url.url).success(function (data) {
                $scope.websites = data.websites;
        });
        };
    }]);

This is my HTML: 这是我的HTML:

<form ng-controller="ListWebsiteCtrl">
    <input title="get_url.url" ng-model="get_url.url">
    <button ng-click="set(get_url.url)">INSERT WEBSITE</button>
    <table class="table">
        <tr>
            <th>ID</th>
            <th>URL</th>
            <th>Status</th>
        </tr>
        <tr>
            <th>{{ websites.id }}</th>
            <th>{{ websites.url }}</th>
            <th>{{ websites.status }}</th>
        </tr>
    </table>
</form>

What is the most efficient way to do it? 最有效的方法是什么?

Use Indexed DB It is a low-level API for client-side storage of significant amounts of structured data, including files/blobs. 使用索引数据库这是用于客户端存储大量结构化数据(包括文件/ blob)的低级API。 This API uses indexes to enable high-performance searches of this data. 该API使用索引来启用对此数据的高性能搜索。 While Web Storage is useful for storing smaller amounts of data, it is less useful for storing larger amounts of structured data. Web存储可用于存储少量数据,而对存储大量结构化数据则不太有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM