Solved

Get response from ajax/php to a div

Posted on 2010-11-19
3
823 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

691 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