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 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need to return a Session Variable after Ajax Request

    Hi,

    I have multiple forms on a page that I submit using ajax, it send a product_id so it knows which one to update, with limitations out of my control it regenerates a new product_id for the product just updated.

    The problem I have is if a user is updating a product in their basket, it updates each product, but when they make a second alteration to the product without a page refresh which I want to avoid it does not update the product because the product id has changed.

    During the update of a product once the new product id is generated it places it into $_SESSION['new_products_id_in_cart'] = $products_id;

    What I need to do is once my form is submitted with Ajax, to return that session variable and place the result of this into an input box, ready for the next time the for is updated.

    At the moment I'm using Jquery Form to handle Ajax requests, but can change that if needed.

    I really hope someone can help, if you don't quite understand please let me know.



    Thank!

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    And what prevents you from getting that session variable received by the AJAX object in a response?

    I presume you simply post data using AJAX. If you will use a GET, you may get also a response from that PHP application, while the submitted data is sent to the DataBase;

    In a schematic sequence:

    - use GET as method in AJAX wile sending data to a php external code
    - the php code should open connection, post data to DB (MySQL code INSERT), get the new $product_id (MySQL code SELECT), close the connection and echoes back that id (to the AJAX object) as responseText
    Last edited by Kor; 11-10-2010 at 01:16 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Kor for the reply.

    How would I place the result of the $_GET into a form input box from the response?

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I don't work with JQuery (nor with other libraries unless I am forced to - it is not the case with AJAX codes) thus I can not give you a JQuery solve.

    But in native JavaScript, there must be something like:
    Code:
    ...
    AJAXobj.onreadystatechange=function(){
    if(AJAXobj.readyState == 4){
    if(AJAXobj.status == 200){
    var id=AJAX.responseText;
    var textBox=document.getElementById('textboxid');
    textBox.value=id;
    }
    }
    }
    ...
    So, if you find how to get that responseText value in JQuery, the rest is simple.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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