2011-11-17 221 views
-1

我有一个访问Web服务的页面。如何动态创建html页面?

索引页调用onLoad,一个webservice方法来获取数据库列表。 我想在按钮列表上显示结果,每个按钮都包含一个数据库名称。

只使用html和jquery/js,动态创建此页面的最佳方式是什么?

+1

以什么格式从webservice返回数据? – James

+0

@ 999数据来自json,但我可以处理它! –

回答

0

尝试jQuery的模板,你可以在这里找到:http://api.jquery.com/category/plugins/templates/

这是从该链接:

注:jQuery开发团队已经决定不采取这个插件过去的测试版。 它不再被积极开发或维护。文档 暂时保留(仅供参考),直到准备好合适的 替换模板插件。

我不能写一个新的答案,因为问题是封闭的,所以我决定写在这里,如果你不介意。

我的网页上有一些部分是动态显示的。 保存数据我用:

function parseJsonIfPossible(code){ 
    try { 
     //return JSON.parse(code); 
     //console.log(code); 
     return $.parseJSON(code); 
    } catch (e) { 
     return code; 
    } 
} 
function store(to,str){ 
    return parseJsonIfPossible($.ajax({ 
     url: core_url,//this processes the retrieved data 
     global: false, 
     type: "POST", 
     data: {attr : to, val : str}, 
     dataType: "html", 
     async:false, 
     success: function(msg){ 
     //alert(msg); 
     } 
    }).responseText); 
} 

对于歌厅和显示我用

$('#'+file.id).html(responseText);

我希望它能帮助!

+0

看来你明白了什么被问:) –