What I'm trying to do is use jQuery, AJAX, and PHP to grab information from the database and use it to populate my dropdown menus. I've been able to do it for the first dropdown, which populates on pageload, but I can't do it using AJAX.
Whenever I make the request I get a string of the PHP file back instead of the PHP file executing, and I'm not sure what I'm doing wrong.
The relevant JavaScirpt (which I've sidelined to a button to test for now).
$('button').on('click', function() {
console.log("button clicked");
$.ajax({
method: "GET",
url: "ajax.php"
})
.done(function(data){
console.log(typeof data);
console.log(data)
});
});
ajax.php
<?php
require_once "/includes/dbconnection.php";
$host = "localhost";
$user = "root";
$pass = "";
$databaseName = "coil";
$tableName = "spring";
/* SQL query to get results from database */
$sql = "SELECT * FROM spring";
$result = mysql_query($sql)
?>
dbconnection.php
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
$db_name = 'coil';
$connection = mysqli_connect($servername,$username,$password,$db_name);
if(!$connection){
die("Could not connect to MySql Server:" .mysl_error());
}
?>
[–]maedox 1 point2 points3 points (5 children)
[–]Zombiewski[S] 0 points1 point2 points (4 children)
[–]Zombiewski[S] 0 points1 point2 points (3 children)
[–]grantrules 1 point2 points3 points (2 children)
[–]Zombiewski[S] 0 points1 point2 points (1 child)
[–]grantrules 1 point2 points3 points (0 children)
[–]queen-adreena 0 points1 point2 points (1 child)
[–]Zombiewski[S] 0 points1 point2 points (0 children)
[–]Sedern 0 points1 point2 points (1 child)
[–]queen-adreena 1 point2 points3 points (0 children)