我有一个按钮,按下后需要从外部PHP文件调用一个函数并在新页面中加载它。
当我在我的index.php页面上点击“SHOW”按钮时,它会显示保存在“mesaj”中的消息,但会在index.php页面上显示(这不是我想要的!)。
我想要实现的是,当我在我的index.php页面上点击“SHOW”按钮时,它会在另一个名为content.php的PHP页面中显示消息内容。我想设置href。
index.php
当我在我的index.php页面上点击“SHOW”按钮时,它会显示保存在“mesaj”中的消息,但会在index.php页面上显示(这不是我想要的!)。
我想要实现的是,当我在我的index.php页面上点击“SHOW”按钮时,它会在另一个名为content.php的PHP页面中显示消息内容。我想设置href。
index.php
<input type = "button" class="btn btn-primary" id = "show" onClick = "show()" value = "SHOW"/>
functions.php
function show()
{
database();
$sql = "SELECT title FROM `Articles`";
$titleSql = mysql_query( $sql ) or die("Could not select articles:");
$html = '<html><body><div class="container"><h2>Basic List Group</h2><ul class="list-group">';
while ($title = mysql_fetch_array($titleSql)) {
$html .= '<li class="list-group-item">'.$title["title"].'</li>';
}
$html .= '</ul></div></body></html>';
echo $html;
//die(json_encode(array("mesaj" => "Entered data successfully ")));
}
function.js
function show(){
var n = $('#show').val()
$.post("functions.php", {show:n}).done(function(mesaj){
//$(document).html(mesaj);
document.write(mesaj);
});
}