PDA

View Full Version : Dynamic Ajax Content - Utilizing forms



greenowl
02-08-2007, 07:30 AM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem: I have a form on one of loaded pages. Now what I would like this form to do is submit within the ajax script. I already tried this and it wont parse the post values through the ajax.


<form action="javascript:ajaxpage('form.php', 'contentarea');" method="post" name="text">
<input name="test" type="text" />
<input name="Submit" type="Submit" value="Submit" />
</form>

The reason I am wanting to use a form in the ajax code is that my game utilizes a lot of forms, and I would like to use ajax to get the pages. This would make the pages load faster (as they can be image intensive, the static content). SWo it would basically be like a template system and they would not have to load the template over and over again, just the game content.

The game content includes forms which is why I am asking of there is any way to parse the form values through ajax while still using the dynamic ajax content script.

*Sorry if some of my explanation is confusing, I just couldn't think of a way of explaining it.

greenowl
02-09-2007, 11:25 PM
Anyone? I have tried changing the code inside the ajaxpage script to POST instead of GET but it still wont work :s

ddadmin
02-10-2007, 12:13 AM
Posting using Ajax requires a different route internally than GET, so you can't just set the "action" attribute of the form to the script. Generally speaking you need to open up a POST request, and also, send in some relevant header info inside the script. Something like:


ajaxobj.open('POST', url, true);
ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxobj.setRequestHeader("Content-length", parameters.length);
ajaxobj.setRequestHeader("Connection", "close");

You may want to take a look at Basic Ajax routine (http://dynamicdrive.com/dynamicindex17/ajaxroutine.htm), which supports both POST and GET. However, not nearly complete as far as what you're looking to accomplish, so in this case it would definitely help if you're familiar with Ajax and add code on top of it.

greenowl
02-10-2007, 01:09 AM
I am really a complete newbie when it comes to ajax, so I looked at the script you mentioned above. Now I noticed that it alerted the data which is not what I want and so I looked through some code and thought, why not do what the Dynamic content does which is:

document.getElementById("contentarea").innerHTML=myajax.responseText
instead of the alert that it was currently doing.

alert(myajax.responseText)
I also changed the one after it the xml one. However It did not work, which is what is getting me confused about ajax. Because I thought that adding that would work because they are on about the same principal, both sending and receiving data.
Anyone have a clue as to why it is not working?

greenowl
02-13-2007, 03:40 AM
Anything else to add to this or is this the only response I am going to get.