[英]Javascript echoing out HTML rather than processing it
I'm trying to customise the output from a WordPress plugin called Showtime. 我正在尝试自定义名为Showtime的WordPress插件的输出。 Showtime contains the following Javascript to output what is entered in the schedule.
Showtime包含以下Javascript,用于输出计划中输入的内容。 For styling reasons I'm entering into the plugin admin area for a show -
出于样式原因,我正在进入插件管理区域进行表演-
<h3>Drivetime</h3><p>with Davie Boy</p>
The issue I have is this is literally printed out / echoed on the page and the html is not rendered / processed, as though wrapped in pre tags. 我的问题是,这实际上是在页面上打印出来/回显的,并且HTML并未呈现/处理,就像包裹在pre标签中一样。
I understand the following javascript outputs the show, how could I get it to actually not echo the html but process it. 我了解以下javascript输出的显示,我如何才能让它实际上不回显html而是对其进行处理。 Sorry if I'm not using the correct terminology.
抱歉,如果我使用的术语不正确。
Any help much appreciated 任何帮助,不胜感激
rob 抢
UPDATE 更新
Thanks for the comments - to get me thinking. 感谢您的评论-让我思考。 This javascript is getting the Showname from a PHP script called crud.php.
此javascript是从名为crud.php的PHP脚本获取Showname的。 Looking over this I think this may be the offending line in crud.php
仔细研究一下,我认为这可能是crud.php中令人讨厌的行
$showname = htmlentities(stripslashes(($_POST['showname'])));
rather than the javascript itself? 而不是JavaScript本身?
jQuery(function($){
function get_current_show() {
//Get the current show data
$.post(crudScriptURL, {"crud-action" : "read", "read-type" : "current"}, function (currentShowJSON) {
var schedule = $.parseJSON(currentShowJSON);
var outputHTML = '';
var currentShow = schedule['current-show'];
if (currentShow.showName){
var currentShowName = currentShow.showName;
var imageURL = currentShow.imageURL;
var linkURL = currentShow.linkURL;
var startClock = currentShow.startClock;
var endClock = currentShow.endClock;
outputHTML += '<div id="showtime">'+currentShowName+'</div>';
if (imageURL){
if (linkURL){
outputHTML += '<a href="'+linkURL+'"><img class="showtime-image-thumbnail" src="'+imageURL+'" alt="'+currentShow.showName+'" /></a>';
} else {
outputHTML += '<img class="showtime-image-thumbnail" src="'+imageURL+'" alt="'+currentShow.showName+'" />';
}
}
} else {
outputHTML += '<h3 class="current-show">'+currentShow+'<h3>';
}
var upcomingShow = schedule['upcoming-show'];
if (upcomingShow){
var upcomingShowName = upcomingShow.showName;
var upcomingShowLink = upcomingShow.linkURL;
var upcomingStartClock = upcomingShow.startClock;
var upcomingEndClock = upcomingShow.endClock;
if (upcomingShowLink){
outputHTML += '<h3 class="upcoming-show"><strong>Up next:</strong> <a href="'+upcomingShowLink+'">'+upcomingShowName+'</a></h3>';
} else {
outputHTML += '<h3 class="upcoming-show"><strong>Up next:</strong> '+upcomingShowName+'</h3>';
}
outputHTML += '<span>'+upcomingStartClock + ' - ' + upcomingEndClock + '</span>';
}
$('.showtime-now-playing').html(outputHTML);
//Set a timer to update the widget every 30 seconds
setTimeout (get_current_show, (30 * 1000));
});
}
get_current_show();
});
If you have a consistent format for these, and don't really need to use symbols as part of the display, you can implement a sort of parser in the jquery function. 如果这些格式具有一致的格式,并且实际上不需要在显示中使用符号,则可以在jquery函数中实现某种解析器。 For example, you could enter
<h3>Drivetime</h3><p>with Davie Boy</p>
, and in the code do something like: 例如,您可以
<h3>Drivetime</h3><p>with Davie Boy</p>
输入<h3>Drivetime</h3><p>with Davie Boy</p>
,然后在代码中执行以下操作:
var currentShowName = $('<div/>').html(currentShow.showName).text();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.