Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2010
    Location
    Orlando, FL
    Posts
    161
    Thanks
    4
    Thanked 8 Times in 8 Posts

    Question How would I obtain the post value from a form submitted on previous page?

    I couldn't decide which thread was most suitable for this question, seeing as how I'm not sure if it's a javascript, jQuery, JSON, or AJAX issue, so I apologize if this is in the wrong place.

    I have a form on a page named build_cake.php. It is only there to utilize the POST method. I stringified an object with JSON-js and set it to the value of the input from the aforementioned form. *See code below*

    Code:
    var jsonText = JSON.stringify(cake); \\stringify the object titled 'cake' and store it to the variable 'jsonText'
    var myForm = "<form id='temporary_form' action='verify_cake.php' method='POST'><input id='passedObject' name='passedObject' value='" + jsonText + "' /></form>"; \\create the form and set the value= jsonText
    $(myForm).submit(); \\submit form
    Now, I know it works because I can get the string with PHP on the 'verify_cake.php' page using the POST method. However, is there a way for me to get this string with either javascript, jQuery, JSON, or AJAX? If so, could someone point me in the right direction? I know there is a POST method for AJAX and jQuery, but I was under the impression that is to send data to another page while staying on your current page. I need to take this cake object with me to a new page.

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,451
    Thanks
    17
    Thanked 275 Times in 275 Posts
    Since you're using PHP you can always set it as a$_SESSION variable and if it isset on the page your're going to, get it from there.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    you have to echo the POST data back to JS from PHP. you can use echo json_encode($thePostDataObject) in php to turn the object into JSON, which you can assign to a variable in a <script> block to reach from JS.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    Tags for this Thread

    Posting Permissions

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