Hi guys,

I am using this tutorial:

http://www.w3schools.com/ajax/tryit....=tryajax_first

where if you click a button, the the content of my div container is replaced with a message saying thank you for your submission. However, you cannot assign this to a submit button as it just ends up refreshing the page. I need a submit button to submit some items inside a form. Therefore, is there a way to submit the contents of a form and show the message like in the tutorial without the page refreshing to its normal state?

Any help would be fantastic.
Thanks.

Yeah you cannot use submit button as it will refresh the whole page. You will have to use a normal button.
Now in the line
xmlhttp.open("GET","ajax_info.txt",true);
instead of "ajax_info.txt" use the url where you want to submit the form i.e. the one in the action attribute of a form and append the form elements you want to submit to this url.

You can also use POST method to submit form elements through ajax.
See a tutorial here,
http://www.openjs.com/articles/ajax_xmlhttp_using_post.php

I can get it so that it loads the page that the info should be passed to using ajax, but the sessions arent submitted. any ideas?

If you are maintaining sessions by using some hidden input element or url rewriting than I think passing the session parameters in the ajax request should do it.
I have used session tracking APIs in JSP/Servlets so dont have detail idea on this and wont be help to help much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.