如何基于 JSON 更改显示值/颜色 td
我正在开发一个应用程序,通过 ajax 调用获取 json。此 json 包含对象,您可以在其中获取每个分机的特定状态代码(1 = 在线,2,正在响铃,3 = 忙碌)
我如何确保返回的值转换为文本(最好使用不同颜色的文本) )
所以当我得到 1 回来时,我希望它显示在线,并带有 2 环等
$.ajax({
type:'GET',
url: url,
dataType: 'json',
error: function(jqXHR, exception) {ajax_error_handler(jqXHR, exception);},
success: function(data){
// console.log(JSON.parse(data.responseText));
// console.log(JSON.parse(data.responseJSON));
console.log(data['entry']);
var event_data = '';
$.each(data.entry, function(index, value){
/* console.log(data['entry']);*/
event_data += '<tr>';
event_data += '<td>'+value.extension+'</td>';
event_data += '<td>'+value.status+'</td>';
<!--event_data += '<td>'+value.registration+'</td>';-->
event_data += '</tr>';
});
$("#list_table_json").append(event_data);
},
error: function(d){
/*console.log("error");*/
alert("404. Please wait until the File is Loaded.");
}
});
提前致谢!
I'm working on an app where I get a json via an ajax call. This json contains objects where you get a certain status code per extension (1 = online, 2, is ringing, 3 = busy)
How can I ensure that the value that I get back is converted to the text (preferably with a different color of the )
So when I get a 1 back I want it to show Online, and with a 2 Ring etc
$.ajax({
type:'GET',
url: url,
dataType: 'json',
error: function(jqXHR, exception) {ajax_error_handler(jqXHR, exception);},
success: function(data){
// console.log(JSON.parse(data.responseText));
// console.log(JSON.parse(data.responseJSON));
console.log(data['entry']);
var event_data = '';
$.each(data.entry, function(index, value){
/* console.log(data['entry']);*/
event_data += '<tr>';
event_data += '<td>'+value.extension+'</td>';
event_data += '<td>'+value.status+'</td>';
<!--event_data += '<td>'+value.registration+'</td>';-->
event_data += '</tr>';
});
$("#list_table_json").append(event_data);
},
error: function(d){
/*console.log("error");*/
alert("404. Please wait until the File is Loaded.");
}
});
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经更改了代码
function get_blf() {
$.ajax({
类型:'获取',
网址: 网址,
数据类型:'json',
错误:函数(jqXHR,异常){ajax_error_handler(jqXHR,异常);},
成功: function(data){
}
并添加 css,但现在我无法获取任何值。但现在我无法取回任何值。 (抱歉,我对 javascript 还很陌生)
I have change the code
function get_blf() {
$.ajax({
type:'GET',
url: url,
dataType: 'json',
error: function(jqXHR, exception) {ajax_error_handler(jqXHR, exception);},
success: function(data){
}
and add the css, but now i can't get any values back. but now i can't get any values back. (sorry I'm fairly new to javascript)
请使用 DOM API
获取颜色的一种方法是使用 CSS 类来表示状态:
Please use the DOM API
One way of getting colors would be to use CSS classes for the status:
我终于让脚本工作了。我现在正在尝试构建轮询,但是我看到 ajax 调用再次执行并获取了数组。但是,该表没有刷新,而是添加了一个新表,有谁知道这个问题的解决方案吗?
我现在用于重新轮询的代码是
}
I finally got the script working. I am now trying to build in a polling, however I see that the ajax call is executed again and the array is fetched. However, the table is not refreshed but a new table is added, does anyone know a solution for this?
code I'm using now for the repoll is
}