Reputation: 3286
I have a div that displays text from a php session:
<div id="sessioncontent">
<?php if (isset( $_SESSION['returntext'])){ echo $_SESSION['returntext'];} ?>
</div>
I have a javascript method that calls another php script which changes the text within that session variable. At the end of the method, I want the div to refresh so that the new text within the session is echoed. I have tried the following line but it doesnt work:
document.getElementById("sessioncontent").innerHTML = document.getElementById("sessioncontent").innerHTML;
Upvotes: 0
Views: 520
Reputation: 10014
You are replacing content with the same content. I would suggest making an ajax call and then populating your div with the response from the ajax call. Something like this:
$.ajax({
url: yourUrl,
method: 'get', // or 'post'
success: function (response) {
$('#sessioncontent').html(response);
}
// other ajax options here if you need them
});
Upvotes: 1
Reputation: 1392
Too, complicated. First, display the initial div content w/ out the PHP code (i.e. the output of the PHP). Second, your wording doesn't makes complete sense - JavaScript does not call PHP. I'm going to assume you mean Ajax. Once you get the new session variable from an ajax call, then you can update your div dynamically.
I think you are a bit fuzzy on your concepts, which is fine, I'm sure that is why you posted.
Upvotes: 0