简体   繁体   English

保存数据而不刷新页面

[英]Save Data Without Refreshing The Page

I have a view that refresh the time of a model in database whenever it's called. 我有一个视图,无论何时调用它都会刷新数据库中模型的时间。

def data(request):
    new = Data.objects.filter(user=request.user)
    if new:
        new.update(timestamp=timezone.now())

This view is related to the URL, 此视图与URL相关,

url(r'^data/$', views.data, name='data')

So, how can I call this view & update the time in database when user click a URL or a button without refreshing the page? 因此,当用户单击URL或按钮而不刷新页面时,如何调用此视图并更新数据库中的时间?

Proceeding from the comments: 从评论开始:

In the html: 在html中:

<button type="button" id="someid" onclick="idclick()">Click me</button>

In the javascript: 在javascript中:

function idclick() {
    ....
    return false;
}

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

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