I have a page that use javascript innerhtml to replace the contents of an element as a pseudo-static page.
我有一个页面,使用javascript innerhtml将元素的内容替换为伪静态页面。
The following code is from the current content of that element:
以下代码来自该元素的当前内容:
<?php
$con = mysql_connect('***********', '******', '**********');
mysql_select_db(dbbmdmi);
if ($con) {
$sql = "SELECT TeamID, Captain, CountryID, ArrDate, DepDate FROM Teams";
$result = mysql_query($sql) or die(mysql_error());
$link = "<a id='" . $row["TeamID"] . "' onClick='SetTeamID();ReplaceContentInContainer('content','replace_target6')'>Edit</a>";
if ($result) {
// output data of each row
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "Captain: " . $row["Captain"]. "<a id='" . $row["TeamID"] . "' onClick=\"ReplaceContentInContainer2('content','<?php include 'scripts/editteam.php?TeamID=" . $row["TeamID"] . "'>')\">Edit</a>;" . "</br>Country: " . $row["CountryID"]. "</br>Dates: " . $row["ArrDate"]. " - ". $row["DepDate"]. "<br>";
}
?>
In onClick=\"ReplaceContentInContainer2('content','<?php include 'scripts/editteam.php?TeamID=" . $row["TeamID"] . "'>')
I'm trying to pass the php include as the "source" argument to the following function in the original "container" page:
在onClick = \“ReplaceContentInContainer2('content',' ')我正在尝试传递php include as原始“容器”页面中以下函数的“source”参数:
<script type="text/javascript">
function ReplaceContentInContainer2(target,source) {
document.getElementById(target).innerHTML = source;
}
</script>
I keep getting this error when I click the link:
当我点击链接时,我不断收到此错误:
teams.php:1SyntaxError: Unexpected identifier 'scripts'. Expected ')' to end a argument list.
teams.php:1SyntaxError:意外的标识符'脚本'。预期')'结束参数列表。
Basically, I'm trying to pass the $row_["TeamID"] to the next page in the address so that I can call with a
$_GET` function.
基本上,我正在尝试将$ row _ [“TeamID”]传递到地址中的下一页,以便我可以使用$ _GET`函数调用。
Any suggestions?
UPDATE:
After escaping the single quotes in the javascript function call, the content of the element is replaced as it should be, except the php include is being rendered in the new content as an html comment, rather than run as php.
在javascript函数调用中转义单引号后,元素的内容将被替换为应有的,除了php include在新内容中呈现为html注释,而不是作为php运行。
escaped single quotes in onClick=\"ReplaceContentInContainer2('content','<?php include \'scripts/editteam.php?TeamID=" . $row["TeamID"] . "\'?>')\"
在onClick = \“ReplaceContentInContainer2('内容',' ')\”中转义单引号
rendered html: <!--?php include 'scripts/editteam.php?TeamID=Kellog'?-->
渲染html:
1 个解决方案
#1
0
That is a very interesting idea. The problem that you're going to run into is that the PHP is just going to render a string of your <?php include... ?>
because PHP only handles in it initially and then hands it off. Here is probably what you'll want to do.
这是一个非常有趣的想法。您将遇到的问题是PHP只是要呈现 的字符串,因为PHP最初只处理它,然后将其交给它。这可能是你想要做的。
<!-- front-end.html-->
<script type="text/javascript">
function ReplaceContentInContainer2(target,source) {
document.getElementById(target).innerHTML = source;
}
function ajaxForHtml(url, callback) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
callback(xhttp.responseText);
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
function clickAction(id) {
ajaxForHtml('scripts/editteam.php?TeamID=' + id, function(data) {
ReplaceContentInContainer2('content', data);
});
}
</script>
<?php
$con = mysql_connect('***********', '******', '**********');
mysql_select_db(dbbmdmi);
if ($con) {
$sql = "SELECT TeamID, Captain, CountryID, ArrDate, DepDate FROM Teams";
$result = mysql_query($sql) or die(mysql_error());
$link = "<a id='" . $row["TeamID"] . "' onClick='SetTeamID();ReplaceContentInContainer('content','replace_target6')'>Edit</a>";
if ($result) {
// output data of each row
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo sprintf('Captain: %s <a id="%d" onclick="clickAction(%d);">Edit</a>;</br>Country: %d</br>Dates: %s - %s </br>',
$row['Captain'], $row['TeamId'], $row['TeamId'], $row["CountryID"], $row["ArrDate"], $row["DepDate"]
);
}
#1
0
That is a very interesting idea. The problem that you're going to run into is that the PHP is just going to render a string of your <?php include... ?>
because PHP only handles in it initially and then hands it off. Here is probably what you'll want to do.
这是一个非常有趣的想法。您将遇到的问题是PHP只是要呈现 的字符串,因为PHP最初只处理它,然后将其交给它。这可能是你想要做的。
<!-- front-end.html-->
<script type="text/javascript">
function ReplaceContentInContainer2(target,source) {
document.getElementById(target).innerHTML = source;
}
function ajaxForHtml(url, callback) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
callback(xhttp.responseText);
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
function clickAction(id) {
ajaxForHtml('scripts/editteam.php?TeamID=' + id, function(data) {
ReplaceContentInContainer2('content', data);
});
}
</script>
<?php
$con = mysql_connect('***********', '******', '**********');
mysql_select_db(dbbmdmi);
if ($con) {
$sql = "SELECT TeamID, Captain, CountryID, ArrDate, DepDate FROM Teams";
$result = mysql_query($sql) or die(mysql_error());
$link = "<a id='" . $row["TeamID"] . "' onClick='SetTeamID();ReplaceContentInContainer('content','replace_target6')'>Edit</a>";
if ($result) {
// output data of each row
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo sprintf('Captain: %s <a id="%d" onclick="clickAction(%d);">Edit</a>;</br>Country: %d</br>Dates: %s - %s </br>',
$row['Captain'], $row['TeamId'], $row['TeamId'], $row["CountryID"], $row["ArrDate"], $row["DepDate"]
);
}