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
Solved

Get response from ajax/php to a div

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

856 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