Results 1 to 5 of 5

Thread: Dynamic Ajax Content - Utilizing forms

  1. #1
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic Ajax Content - Utilizing forms

    1) Script Title: Dynamic Ajax Content

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...jaxcontent.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.

    Code:
    <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.

  2. #2
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Anyone? I have tried changing the code inside the ajaxpage script to POST instead of GET but it still wont work :s

  3. #3
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    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:

    Code:
    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, 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.

  4. #4
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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:
    Code:
    document.getElementById("contentarea").innerHTML=myajax.responseText
    instead of the alert that it was currently doing.
    Code:
    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?

  5. #5
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Anything else to add to this or is this the only response I am going to get.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •