前端代码
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse){
console.log("收到来自content-script的消息:");
var pageinfo=new Array(request.msg);
console.log(pageinfo);
var rep=$.ajax({
type:"post",
url:"http://127.0.0.1/mysqlhelper.php",
dateType:"json",
async:true,
date:{'pageinfo':pageinfo},
error: function(request) {
console.log("Connection error");
},
success: function(res) {
console.log(res);
}
});
});
PHP代码
$pageinfo=$_POST['pageinfo'];
$pageinfoarr=explode('@',$pageinfo);
print_r($pageinfoarr);
$servername="127.0.0.1";
$username="root";
$password="Yaoxiuyi@123";
$conn=new mysqli($servername,$username,$password);
if($conn->connect_error){
die("could not connect:".mysql_error());
}
echo"connect successfully";
$idval=$pageinfoarr[0];
$sql="select * from skulink where id='{idval}'";
$result=$conn->query($sql);
if($result->rows>0){
while($row=$result->fetch_assos()){
echo"id:".$row["id"];
}
}else{
echo"0 results";
}
?>
控制台提示
收到来自content-script的消息:
background.js:6 ['636364439288@蓝盘间金主图款@柠檬黄@黑盘@蓝盘银色@黑盘绿圈@蓝盘银带@20144']
Warning: Undefined array key "pageinfo" in D:\webroot\phplearn\mysqlhelper.php on line 5
Array
(
[0] =>
)
connect successfully
Warning: Attempt to read property "rows" on bool in D:\webroot\phplearn\mysqlhelper.php on line 22
0 results