如何在 jQuery 中输出 JSON 列
我正在使用 qTip jQuery 插件来创建动态工具提示。工具提示将 id 发送到 cfc,该 cfc 运行查询并返回 JSON 格式的数据。
目前,工具提示加载以下内容:
{"COLUMNS:" ["BOOKNAME","BOOKDESCRIPTION"["MYBOOK","MYDESC"]]}
Here's the jQuery
$('#catalog a[href]').each(function()
{
var gi = parseInt($(this).attr("href").split("=")[1])
$(this).qtip(
{
content: {
url: 'cfcs/viewbooks.cfc?method=bookDetails',
data: { bookID: gi },
method: 'get',
title: {
text: $(this).text(),
button: 'Close'
}
},
api :{
onContentLoad : function(){
}
},
});
});
正如我所提到的,数据已成功返回,但我不确定如何输出它并使用 HTML 格式化它。
我尝试添加 content: '
' + data.BOOKNAME
+ '
:{ onContentLoad : function(){ .....
to see if I could get it to output something, but I get a 'data is undefined error'尝试使用 HTML 格式输出此数据的正确方法是什么?
I'm using the qTip jQuery plugin to create dynamic tool tips. The tooltip sends an id to a cfc which runs a query and returns data in JSON format.
At the moment, the tooltip loads with the following:
{"COLUMNS:" ["BOOKNAME","BOOKDESCRIPTION"["MYBOOK","MYDESC"]]}
Here's the jQuery
$('#catalog a[href]').each(function()
{
var gi = parseInt($(this).attr("href").split("=")[1])
$(this).qtip(
{
content: {
url: 'cfcs/viewbooks.cfc?method=bookDetails',
data: { bookID: gi },
method: 'get',
title: {
text: $(this).text(),
button: 'Close'
}
},
api :{
onContentLoad : function(){
}
},
});
});
As I mentioned, the data is returned successfully, but I am unsure how to output it and format it with HTML.
I tried adding content: '<p>' + data.BOOKNAME
+ '
' to api :{ onContentLoad : function(){ .....
to see if I could get it to output something, but I get a 'data is undefined error'
What is the correct way to try and output this data with HTML formatting?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 qTip 论坛来看,作者似乎正在添加api 回调中的 ajax 调用。也许这能解决你的问题?
这是他的例子:
From the qTip forums, it appears that the author is adding an ajax call inside the api callback. Maybe that will solve your problem?
Here is his example:
您必须在请求中将 dataType 指定为 json。它告诉 jquery 将响应视为 json,以便您可以像当前一样使用它。此外,一旦您获得了数据,您就可以创建 HTML 来显示。
You have to specify the dataType as json in your request. It tells jquery to treat the response as json, so that you can use it as you are using currently. Also once you get the data as son you can create HTML to display.
这是另一种情况,当打开请求调试输出时,ColdFusion 调试器会导致 ajax 错误。这是我们在启用调试的情况下使用 ColdFusion 时需要记住的一大“陷阱”。它破坏了ajax。
This turned out to be another case where the ColdFusion debugger, when request debugging output is turned on, causes an ajax error. This is one big "gotcha" we need to remember when working with ColdFusion with debugging enabled. It breaks down ajax.