Results 1 to 2 of 2

Thread: realtime transfer of variables to php without refresh

  1. #1
    Join Date
    Jun 2007
    Posts
    64
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question realtime transfer of variables to php without refresh

    hello there!

    i was facing this problem whole day and i did not come up with a solution, so i ask you guys for help.

    my code looks like this: (using jquery)

    Code:
    (more code here)
    
    
    $.post("test.php", {encryptedPassword2: encryptedPassword}, function(data){
    console.log(data); //DEBUG: print the result of this action to debug console
    });
    </script>
    
    <?php
    $rsapassword = $_POST['encryptedPassword2'];
    print_r($_REQUEST); //DEBUG: print out all get/post
    echo $rsapassword;
    
    
    (more code here)
    now when i load the page, above this code the script calculates "encryptedPassword" in javascript and in the same page load i want to transfer this variable, so my "$_POST['encryptedPassword2']" is set and can be used further on in the php script without the need of a page refresh...

    in this above example the output of the page load is an error, since the variable isnt set when php calls for it. but in the console output of javascript "console.log(data);" the output looks right. over there the variables are set and print out. so the ajax response comes way later, when page is allready finished loading.


    sorry im not really good in this, so i would appriciate any help!!

    thx in advance

  2. #2
    Join Date
    Jun 2007
    Posts
    64
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    since i believe this is kinda impossible without calling another page or recalling the same, i ended up with sumething else. for those who are intrested ->

    i made it so the calculation i need from javascript plus only the really requiered php code are at top of the script and before the php post variable isnt set by recalling the page via ajax, the rest of the script dies (will be ignored). for example it can dies with a string like "Refreshing..."

    so with this

    Code:
    $('body').replaceWith(http.responseText)
    placed in the ajax-success-function from jquery, it simply replaces the "old" content with the "new" one, that was executed by ajax with the php post variable correctly set.


    this might be a nasty way to do it, but it works...

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
  •