I am trying to send information between 2 files.
first file :
function findDepartment(codePostal,commune,deptId)
{
if (codePostal.length==5)
{
var fichier1 = "inclusions/ajax-cp-departement.php";
$.ajax({
url: fichier1,
data: {codePostal: codePostal, commune: commune},
success: function(response) {
$(deptId).val(response);
},
error: function(xhr) {
alert('Error! Status = ' + xhr.status);
}
});
}
}
Second file : "inclusions/ajax-cp-departement.php"
$commune = $_REQUEST['commune'];
$commune = trim($commune);
$codePostal= $_REQUEST['codePostal'];
$codePostal= trim($codePostal);
if (strlen($commune)>0 && strlen($codePostal)>0)
{
// Liste les communes du département demandé
$query = "SELECT departement
FROM commune_zone
WHERE commune LIKE '$commune'
AND code_postal LIKE '$codePostal'
LIMIT 1";
}
this is how i call my function :
findDepartment(monCp,$("#ville_projet").val(), "#departement_projet");
the commune variable is not detected since it sends an empty result, when i remove commune it works, any ideas why do I have this problem ?