Solved

Get response from ajax/php to a div

Posted on 2010-11-19
3
813 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now