Problem about jQuery form plugin with json
After I created a form. I bind the Form to Ajax and create function
- var pFormOption = {
dataType: 'json',
beforeSubmit: validatePForm,
success: processJson
};
$('#pForm').ajaxForm(pFormOption);
function validatePForm(formData, jqForm, options) {
if($('#pName').val() == ''){
alert('Please fill you name.');
$('#pName').focus();
return false;
{
};
function processJson (data) {
alert(data.message);
$('#pForm').resetForm();
};
And here my php file.
- <?php
$Name = $_POST['pName'];
echo '{ "message": "' . $Name . '" }';
?>
All this working correctly, Return message to alert was correct.
But when I put include function to PHP file like this.
- <?php
include('php/mysql_config.php');
$Name = $_POST['pName'];
echo '{ "message": "' . $Name . '" }';
?>
Function processJson was not call anymore. I debugged with firebug and see php doesn't error and return correctly same as previous code.
And this my mysql_config.php
- <?php
$db_config = array(
'server' => 'localhost',
'user' => 'root',
'pass' => '1234',
'name' => 'budget'
);
?>
I try to not use include, copy all code form this to first php file. It's working.
But I'm still want to know why "include" make a problem.
How can I fix?