<?php
$block_1 = '<p>some text</p>';
$block_2 = '<p>another some text</p>';
?>
<body>
<div id="box"></div>
<a href="">Change!</a>
</body>
$(document).ready(function() {
var a = '1';
var b = '2';
getText(a);
function getText(text) {
$.ajax({
type: "POST",
data: {parametr: text},
url: "text.php",
success: function (text) {
$('#box').empty();
$('#box').append(text);
}
});
}
$(document).on(
'click',
'a',
function(){
getText(b);
}
);
});
if($_POST['parametr'] == '1'){
$block_1 = '<p>some text</p>';
echo $block_1;
} else if($_POST['parametr'] == '2'){
$block_2 = '<p>another some text</p>';
echo $block_2;
}