使用ZPT和Ajax的更新动态地填写表格表格、动态、ZPT、Ajax

2023-09-10 20:46:30 作者:思想在裸奔。

我要创建的金字塔,我想更新表每隔几个secondes一个webproject。我已经决定使用AJAX,但我坚持的东西。

I'm creating a webproject in pyramid where I'd like to update a table every few secondes. I already decided to use ajax, but I'm stuck on something.

在客户端我用下面的code:

On the client side I'm using the following code:

    function update()
    {
    var variable = 'variable ';
    $.ajax({
        type: "POST",
        url: "/diagnose_voorstel_get_data/${DosierID}",
        dataType: "text",
        data: variable ,
        success: function (msg) {
        alert(JSON.stringify(msg));           
        },
        error: function(){
            alert(msg + 'error');
          }                      
        });
    }

金字塔端:

@view_config(route_name='diagnose_voorstel_get_data', xhr=True, renderer='string')    
def diagnose_voorstel_get_data(request):
    dosierid = request.matchdict['dosierid']
    dosieridsplit = dosierid.split     
    Diagnoses = DBSession.query(Diagnose).filter(and_(Diagnose.code_arg == str(dosieridsplit[0]), Diagnose.year_registr == str(dosieridsplit[1]), Diagnose.period_registr == str(dosieridsplit[2]), Diagnose.staynum == str(dosieridsplit[3]), Diagnose.order_spec == str(dosieridsplit[4])))       
    return {'Diagnoses ' : Diagnoses }

现在我想把这个数据表里面有ZPT使用TAL:repeat语句。 我知道如何使用把这个表中的数据在页面加载的时候,但我不知道如何与AJAX结合起来。

Now I want to put this data inside a table with zpt using the tal:repeat statement. I know how to use put this data in the table when the page loads, but I don't know how to combine this with ajax.

可以anny1帮我解决这个问题?感谢adance。

Can anny1 help me with this problem ? thanks in adance.

推荐答案

您可以做的只是与AJAX什么,你是什么意思没有可能?事情变得干净多了,一旦你清楚地看到运行的地方以什么顺序 - 为的Martijn皮特斯指出,有一个在浏览器中没有ZPT,有没有AJAX在服务器上,所以这个问题的标题没有太大的意义

You can do just about anything with AJAX, what do you mean "there's no possibility"? Things become much cleaner once you clearly see what runs where and in what order - as Martijn Pieters points out, there's no ZPT in the browser and there's no AJAX on the server, so the title of the question does not make much sense.

一些选项有:

克伦特发送一个AJAX请求,服务器执行其服务器端的东西,在AJAX调用成功处理程序的客户端重新加载使用类似 window.location.search ='TS =整页+ some_timestamp_to_invalidate_cache 。整个页面将重新加载新数据 - 虽然它的工作原理几乎完全像一个正常的表单提交,使用AJAX像这样没有太大意义的。

clent sends an AJAX request, server does its server-side stuff, in the AJAX call success handler the client reloads the whole page using something like window.location.search='ts=' + some_timestamp_to_invalidate_cache. The whole page will reload with the new data - although it works almost exactly like a normal form submit, not much sense using AJAX like this at all.

客户端发送一个AJAX请求,服务器返回一个HTML的片段的渲染与ZPT的客户端然后附加一些元素在AJAX成功处理您的网页上:

client sends an AJAX request, server returns an HTML fragment rendered with ZPT which client then appends to some element on your page in the AJAX success handler:

function update()
{
    var variable = 'variable ';
    $.post("/diagnose_voorstel_get_data/${DosierID}")
       .done(function (data) {'
           $('#mytable tbody').append(data);
      });
}

客户端发送一个AJAX请求,服务器返回一个JSON对象,通过它来渲染使用客户端模板引擎之一在客户机上。这可能才有意义,如果你使你的整个应用程序在客户端和服务器提供的所有数据,JSON。

client sends an AJAX request, server returns a JSON object which you then render on the client using one of the client-side templating engines. This probably only make sense if you render your whole application on the client and the server provides all data as JSON.

 
精彩推荐
图片推荐