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: