I'm trying to troubleshoot my PHP and JQuery but unable to do so. I've tried using an alert box and console.log to capture the error.However, in the former I only receive [object object] and in the latter, nothing get's published to the console.
Jquery is calling a PHP script to register a user, but is unable to do so.:
$.ajax({
type: 'POST',
url: '/study/scripts/register.php',
data: {firstName:firstName, lastName:lastName, email:email},
cache: false,
error: function(data)
{
alert(data);
alert("Bad");
},
success: function(data)
{
alert(data);
alert("Good");
}
});
PHP:
<?
require ('../include/config.php');
class regForm
{
//Constructor Function
public function __construct()
{
global $db;
$db = new dbConnect;
//Error Flag
global $errorFlag;
$errorFlag = 0;
}
/*other input validation functions here. They work fine and have been tested*/
}
$form = new regForm;
$tableName = 'user';
$columnName = array('first_name', 'last_name', 'email_id');
$columnValue = array($firstName, $lastName, $email);
$db->insert($tableName, $columnName, $columnValue);
?>
Update:
I enabled preserve log and 'LogXMLhttprequests' in the console settings after which i have received this error:
VM174 jquery.min.js:2 XHR failed loading: POST "http://localhost/study/scripts/register.php".<br>
send @ VM174 jquery.min.js:2<br>
ajax @ VM174 jquery.min.js:2<br>
Register @ VM187 register.js:86<br>
onclick @ (index):121<br>
alert(data);with thisconsole.log(data);and you should read more details aboutalertfunctionalert()can't show complex types whileconsole.log()can. However, I don't actually see your PHP outputting anything so I'm not sure what result you expect your callback to get?