0

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.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by parry_kulk
0

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

0

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?

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.