Wednesday, 11 September 2013

Can "dynamic Ajax" exist? One that updates itself?

Can "dynamic Ajax" exist? One that updates itself?

Is there a way to make ajax update its own code while executing? I work
with sessions a lot and this would very much ease my job if it's possible.
This is something like what I'm attempting to (unsuccessfully) do:
<!-- index.php (lots of code omitted) -->
<div id="ajax"><?php include 'ajax.php' ?></div>
and
<!-- ajax.php -->
<?php
session_start();
if(!isset($_SESSION["test"])) $_SESSION["test"] = "not set";
else $_SESSION["test"] = "set";
?>
<script>
$('#somebutton').click(function(){
$.ajax({
url: 'ajax.php',
dataType: 'html',
success: function(result){
$('#ajax').html(result);
$('#somediv').html('<?php echo $_SESSION["test"] ?>');
}
});
});
</script>
If what I'm trying to do is possible, what is wrong with this code?

No comments:

Post a Comment