Hello, At the moment I have a contact form (will post all the code below), I use the AJAX function in jQuery to post all the information over to the PHP file but then I would like it to post back varibles not HTML. The reason for this is that I would like a var allDone which will = false but if it is all good then I know which animation path to take. IE fade back in and flash or just fade out and say thanks! Can this be done?
var name = $('input#name').val(); var email = $('input#email').val(); var subject = $('input#subject').val(); var message = $('textarea#message').val();
This is easily enough achieved. You simple specify a dataType option of "json" in your jQuery ajax call and have your php script return a json object instead of an html fragment.
At the moment I have a contact form (will post all the code below), I use the AJAX function in jQuery to post all the information over to the PHP file but then I would like it to post back varibles not HTML. The reason for this is that I would like a var allDone which will = false but if it is all good then I know which animation path to take. IE fade back in and flash or just fade out and say thanks!
Can this be done?
Here is my code :)
HTML
JQUERY
$(function(){
$('input#submit').click(function(){
$('.loader').fadeIn(\"slow\");
$('input#submit').fadeOut(\"fast\");
$('#theyFill').animate({opacity: 0.3}, 500);
var name = $('input#name').val();
var email = $('input#email').val();
var subject = $('input#subject').val();
var message = $('textarea#message').val();
var allDone = false;
$.ajax({
type: 'post',
url: 'theSender.php',
data: 'name=' + name + '&email=' + email + '&subject=' + subject + '&message=' + message + '&allDone' + allDone,
success: function(results){
$('.loader').fadeOut('slow');
$('input#submit').animate({opacity: 1.0}, 3000).fadeIn(\"slow\");
if(allDone == true){
$('#results').html(\"allDone is now true\");
}else{
$('#results').html(\"allDone is still false\");
}
//$('#results').html(results);
}
});// end of ajax
});
});
And the PHP
Thanks for any help :)
$.ajax({
type: 'post',
url: 'theSender.php',
dataType: 'json',
... snip
http://docs.jquery.com/Specifying_the_D ... X_Requests
Thanks so much for your help :)!