Solved

Get response from ajax/php to a div

Posted on 2010-11-19
3
815 Views
Last Modified: 2012-06-27
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
Comment
Question by:cbielich
3 Comments
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34178821

$.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
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 34179809
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
 
LVL 1

Author Comment

by:cbielich
ID: 34183588
As soon as I get back today from a mini vacation I'll try it out.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question