douyu9433 2018-06-09 16:36
浏览 56

无法从php DB获取数据到javascript

I am quite new to JavaScript and PHP.

I have started lately on my free time to develop a chrme extension to grab some data from db on a hosting server.

I have created a php file and upload it to the server, this file will be called from my extension js file and will connect to the DB to execute a query and return the result back.

everything goes fine except I dnt see the data, it keeps sending me null info.

Connection is ok, credentials are good but somiething is missing.

PHP code:

<?php
header("Access-Control-Allow-Origin: *");

$name = $_POST['name'];

$servername = "139.162.132.71";
$username = "evhoodco_EVhdAdm";
$password = "******";
$dbname = "evhoodco_EVhd623Vehicles";

// Create connection

$dbhandle = new mysqli($servername, $username, $password, $dbname);

if (!$dbhandle)
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
else{
    echo "Success to connect to MySQL";
}

$result = $dbhandle->query("SELECT 1");

if ( false===$result ) {
  printf("error: %s
", mysqli_error($con));
}
else {
  echo ' ... done...';
}

echo json_encode($result);

mysqli_close($dbhandle);
?>

JavaScript code:

$(document).ready(function(){

        $.post('http://evhood.com/connDB.php','name=bob').done(function(data){
           chrome.bookmarks.create({'parentId': "1",'title': '','url': "http://www.sapo.pt"}); 
           console.log(data);    

        });

});

And this is the debug window result:

debug

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 易康econgnition精度验证
    • ¥15 线程问题判断多次进入
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致