Sunday, 1 September 2013

Can't get Result of Ajax Call

Can't get Result of Ajax Call

I'm sending a request to a php file from a form using Ajax. And I want to
receive a result from this php file.
Here's my code :
<script type="text/javascript">
jQuery(document).ready(function($){
$('#devis_gratuit').submit(function(e){
e.preventDefault();
$.getJSON(
'mail.php', {
prestation: $('.prestation-input').val(),
heures: $('.heures-input').val(),
nom: $('.nom-input').val(),
ville: $('.ville-input').val(),
prenom: $('.prenom-type').val(),
code_postal: $('.code_postal-input').val(),
tel: $('.tel-input').val(),
email: $('.email-status').val()},
function(data){
alert("A"); //Doesn't work
$('#status').hide();
$('#status').html('')
.append('<b>Paramètre en majuscule</b> :
'+data.response+'<br/>');
$('#status').fadeIn();
}
);
});
});
</script>
and my php code mail.php:
if(isset($_GET['prestation'])
&& isset($_GET['heures'])
&& isset($_GET['nom'])
&& isset($_GET['prenom'])
&& isset($_GET['ville'])
&& isset($_GET['code_postal'])
&& isset($_GET['tel'])
&& isset($_GET['email']))
{
$response = "Ok";
die($response); //Doesn't work
}
else {
$response = "Ko";
die($response); //Doesn't work
}
$return = array('response' => $response);
header('Content-type: application/json');
But it looks like it's not getting on the PHP file and I see on firebug
that the request is Sent successfully. Any help please ? Thank you.

No comments:

Post a Comment