I have 2 divs: one is a data from php variable:
<div id="data"><?php echo "$strstr"?></div>
Second is the div for ajax request:
<div id="divButton">[CLICK ME]</div>
Here is js code:
$("#divButton").on("click", function() {
$.ajax({
type: "POST",
url: "test.php",
dataType: "json",
data: {simpledata:12345},
success : function(data) {
if (data.code == 200)
console.log("Success!");
else console.log("Error!");
}
});
And finally php code:
<?php
$strstr = "A";
if ($_POST) {
$strstr = $strstr."A";
}
?>
As you can see I need dynamic update of first div, by clicking on second div.
What am I doing wrong?
2
Answers
HTML code Should be
Ajax Call Code
test.php Code Should be
You can’t change the value of $strstr variable by just updating the value of it in you if condition. You need to make an action in your ajax when return is success. Like this
And in your php if condition you must return a string like this