How to make sure that my ajax is properly calling my PHP file. My php file is supposed to print items on the console as well as send data to mysql. Neither are happening and I wonder is it because my Ajax isn't properly calling it?
None of my echos print on the console making me believe that it isn't running.
JS File
var dataString = JSON.stringify(survey.data);
jQuery.support.cors = true;
$.ajax({
type: "GET",
dataType: "json",
url: "connect.php",
data: {dataString},
contentType: "application/json; charset=utf-8",
success: function( data, textStatus, jQxhr ){
$('#response pre').html( data );
},
error: function( jqXhr, textStatus, errorThrown ){
// console.log( errorThrown );
}
});
Connect.php
<?php
echo '$test';
echo '<script>console.log("Your stuff here")</script>';
$json = (file_get_contents("php://input"));
$obj = json_decode($json,true);
header("Content-Type: application/json; charset=UTF-8")
$servername = "127.0.0.1";
$username = "root";
$password = "password";
$dbname = "arc";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>