Jump to content

Recommended Posts

I have tried everything I could find to combine these two AJAX requests into one request,

Is there a doable answer?

<!doctype html>
<html>
  <head>
    <meta  charset=utf-8"/>
    <title>Test sessions</title>
    <script src="../js/jquery.js" ></script>
 </head>
     
<script>
   $(function() {
    $("#btn_test").click(function(){ 
        $.post("sessions_set.php", {
            key: "test_type",
            value: "any old type"
              });
        $.post("sessions_set.php", {
            key: "test_mode",
            value: "any mode"
              });     
            }); 
    }) ;
</script>

<button id="btn_test" />Click

<?php session_start(); 
    $_SESSION{$_REQUEST["key"]} = $_REQUEST["value"];  
?>
Link to comment
https://forums.phpfreaks.com/topic/284764-passing-array-to-ajax/
Share on other sites

i'm curious how you managed to post this thread three times? there have been other recent double/triple posts.

 

did the forum software act like it wasn't accepting the form submission and you hit the submit button multiple times? are you using a mobile device?

Define your array then serialise it using $.param

<script>
    $(function() {
    $("#btn_test").click(function(){ 

        //            key     :    value
        values = { "test_type": "any old type",
                   "test_mode": "any mode" }

        $.post("sessions_set.php", $.param(values));
    });
</script>

In your PHP code you'd use a loop to define the $_SESSION vars

foreach($_GET as $key => $value)
{
    $_SESSION[$key] = $value;
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.