为什么mysql请求的结果不会出现在弹出窗口中?

kmynzznz  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(189)

我正在发现web扩展。在一些例子中,我试图在弹出窗口中显示mysql查询的结果,但弹出窗口中显示的是php的内容。如果我执行php,我得到了好的答案,如果我执行html,我得到了好的答案。你能告诉我是我做错了还是少了什么吗?
清单.json

{   
   "manifest_version": 2,

   "name": "Click to execute",

   "description": "test extension",
   "version": "1.0",

   "icons": {
   "48": "icon.png"   },

   "permissions": [
       "webRequest",
       "webNavigation",
       "tabs", "<all_urls>"   ],

   "browser_action": {
       "default_icon": "icon.png",
       "default_popup": "popup.html"   }

}

弹出窗口.html

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="popup.js"></script>
</head>
<meta charset=utf-8 />
  <body style="width: 300px">
    <div id="clickme"></div>
  </body>
</html>

弹出窗口.js

var xhr;

if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 8 and older
    xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
var data = "";
xhr.open("GET", "select-post.php", true); 
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.overrideMimeType("text/plain");
xhr.send(null);
xhr.onreadystatechange = display_data;
function display_data() {
if (xhr.readyState == 4) {
  if (xhr.status == 200) {
    //alert(xhr.responseText);
    console.log("test1");
    console.log(xhr.responseText);
    console.log("test2");
    document.getElementById("clickme").innerHTML = xhr.responseText;
   } else {
        alert('There was a problem with the request.');
   }
 }
}

select-post.php

<?php

$host="localhost"; 
$username="****";  
$password="**********";
$db_name="********"; 

$con=mysql_connect("$host", "$username", "$password");
mysql_select_db("$db_name");

$sql = "select count(*) as count
from******_posts p
inner join******_postmeta m on m.post_id = p.ID
inner join******_term_relationships r on r.object_id = p.ID
inner join******_terms t on t.term_id = r.term_taxonomy_id
where m.meta_key = '_wpc_expires'
and date_format(from_unixtime(CONVERT(meta_value, SIGNED INTEGER)),'%Y-%m-%d') > current_date
and t.slug = '*************'";

$result = mysql_query($sql);

while($row=mysql_fetch_array($result))
{
echo "<p>".$row['count']."</p>";
}
?>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题