LoneStarJack Posted December 14, 2013 Share Posted December 14, 2013 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 More sharing options...
mac_gyver Posted December 14, 2013 Share Posted December 14, 2013 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? Link to comment https://forums.phpfreaks.com/topic/284764-passing-array-to-ajax/#findComment-1462327 Share on other sites More sharing options...
LoneStarJack Posted December 14, 2013 Author Share Posted December 14, 2013 It looked as if my browser (Firefox) was hung up "waiting for phfreaks.com". I tried to delete two as soon as I say the duplication but didn't find the button or link. Please forgive my impatience by pressing the Post button 3 times. Link to comment https://forums.phpfreaks.com/topic/284764-passing-array-to-ajax/#findComment-1462331 Share on other sites More sharing options...
Ch0cu3r Posted December 14, 2013 Share Posted December 14, 2013 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; } Link to comment https://forums.phpfreaks.com/topic/284764-passing-array-to-ajax/#findComment-1462334 Share on other sites More sharing options...
LoneStarJack Posted December 14, 2013 Author Share Posted December 14, 2013 Thank you I have never used the .param before, but I will read up on it now. Your help is greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/284764-passing-array-to-ajax/#findComment-1462346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.