• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 836
  • Last Modified:

Get response from ajax/php to a div

Below is the code I am using to submit a form with Ajax. What I would like to do is get the response from a php script to the div that I use to fadein when the ajax is a success. Can someone help me out?

My php echos a response such as $msg = 'success' or $msg = 'failure'
$("form#creategroup").submit(function() {
	// we want to store the values from the form input box, then send via ajax below
	var title     = $('#title').attr('value');
	var description     = $('#description').attr('value');
	var duration     = $('#duration').attr('value');
	var contact     = $('#contact').attr('value');
		$.ajax({
			type: "POST",
			url: "includes/addgroup.php",
			data: "?title="+ title +"& description="+ description +"& duration="+ duration +"& contact="+ contact,
			success: function(){
				$('div.hidethis').hide(function(){$('div.success').fadeIn();});
			}
		});
	return false;
	});

Open in new window

<div class="success" style="display:none; width:100%">--The Response Here--</div>

Open in new window

0
cbielich
Asked:
cbielich
1 Solution
 
Sudaraka WijesingheWeb Application ProgrammerCommented:

$.ajax({
                        type: "POST",
                        url: "includes/addgroup.php",
                        data: "?title="+ title +"& description="+ description +"& duration="+ duration +"& contact="+ contact,
                        success: function(message){
                                $('div.hidethis').hide().html(message).fadeIn();
                        }
                });

Open in new window

0
 
leakim971PluritechnicianCommented:
In the success function,

replace : $('div.hidethis').hide(function(){$('div.success').fadeIn();});
by  this : $('div.hidethis').hide(function(){$('div.success').html(message).fadeIn();});

or, better, by :
$('div.success').html(message);
$('div.hidethis').hide(function(){$('div.success').fadeIn();});
0
 
cbielichAuthor Commented:
As soon as I get back today from a mini vacation I'll try it out.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now