SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    POST with Javascript?

    On my webpage I'm using a script that allows users to reorganize some elements in a list. Clicking the "save order" button calls the code below which goes to /fbedit.php?view=favs&order=[a comma-delimited list of numbers is here].

    window.location = "/fbedit.php?view=favs&order=" + ToolMan.junkdrawer().serializeList(document.getElementById(id))
    },

    The problem is that there is too much data for it to be passed this way, so I need to use POST instead of GET. If someone could explain how I could redirect to this same page but pass that comma-delimited list via POST that would be great.

    Thanks!
    Gabe

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use an HTML form with <input type="hidden"> fields. You can use javascript to create these elements on the fly, also, using the createElement and appendChild methods.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    To do a post from JavaScript you would need to populate form fields and then submit the form. You could make a hidden form and load all the values with JavaScript and then submit with JavaScript and then it would not be obvious to the casual visitor that there even is a form.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Guru
    Join Date
    Mar 2004
    Location
    Earth
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Note however that javascript cannot subsequently read post data (except for XHR) - for regular page requests it can only read get data


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
  •