I know there have been tons of questions about setting a PHP session from JQuery and then returning it to JQuery. And I have looked at all of them and still cannot figure out why my code doesn't work. I am trying to use a modal to set a PHP session variable on a back end PHP page and then display it in another modal using jquery, but nothing gets returned.
Here is my sending modal:
<div id="sendingModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-body">
<button id="testSession" type="button" class="btn btn-secondary">Session Test</button>
</div>
</div>
</div>
and here is my back end php:
<?php
session_start();
$_SESSION['testInput'] = $_POST['inputData'];
?>
and here is my receiving modal:
<div id="receivingModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-body">
<div id="testDiv"></div>
</div>
</div>
</div>
Here is my JQuery:
$(document).ready(function() {
$('#testSession').on('click',function(e){
var testData = 'testing 123';
$.post("backendSession.php", {"inputData": testData});
$('#testSession').html(<?=$_SESSION['testInput']?>);
$('#testModal').modal('show');
});
});
What am I doing wrong?
.postcall.$.ajax(). There's asuccesscallback which handles all the returned data after calling the backend script.$.post()and$.get()both call$.ajax()with pre-defined settings. I just prefer using$.ajax()- not saying OP can't use the others.