We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Append AJAX Response Message

hankknight
hankknight asked
on
Medium Priority
392 Views
Last Modified: 2012-08-13
I use the following code to submit a form and get a response using AJAX.

http://d9qjx79zqpo3.googlepages.com/demo.html
http://d9qjx79zqpo3.googlepages.com/sackDemo.zip

When the form has been submitted, a response in placed in placeholder div: "Successfully Saved"

Now you only ever see on response: "Successfully Saved"

I want the response to be APPENDED to the contents of the placeholder div, not to replace the contents.

So if a user submits the form 10 times they should see 10 messages: "Successfully Saved" -- each one under the one before it.
Comment
Watch Question

Commented:
In your line of code that sets the wording in the div - something like:

document.getElementById('divID').innerHTML = 'Successfully Saved';

change to:

document.getElementById('divID').innerHTML = document.getElementById('divID').innerHTML + '<br/>Successfully Saved';
Consultant & Challenge Subduer
CERTIFIED EXPERT
Top Expert 2009
Commented:
"Successfully Saved" comes in the AJAX response. While you could modify SACK, I don't recommend it.

Try this:
var numContainers = 1;
function doit(){
  var box = document.getElementById('container');
  var box2 = document.createElement('div');
  box2.id = 'container'+(++numContainers);
  box.parentNode.insertBefore(box2,box.nextSibling);
	var form = document.getElementById('form');
	ajax.setVar("myTextBox", form.mytext.value); // recomended method of setting data to be parsed.
	ajax.requestFile = "5process.html";
	ajax.method = form.method.value;
	ajax.element = 'container'+numContainers;
	ajax.onLoading = whenLoading;
	ajax.onLoaded = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = whenCompleted;
	ajax.runAJAX();
	scroll(0,9999);
}

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.