I am back to development and need some help or tip.
I want to POST a variable using AJAX on another page but it is not working. My post variable is empty.
my code is (simplified version)
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script>
function logWriter(x){
var str;
switch(x) {
case "A":
str = "hello1";
break;
case "B":
str = "hello2";
break;
default:
//default
}
$.ajax({
type: 'POST',
url: 'm.php',
data: { 'field1': str },
});
};
</script>
<div>
<a href="m.php" onclick = "logWriter('A');">Link 1</a>
<a href="m.php" onclick = "logWriter('B');">Link 2</a>
</div>
the code for m.php
<?php
if(isset($_POST['field1']))
echo $_POST['field1'];
?>
I already searched for this problem over StackOverflow but no success :(
How to pass parameters in $ajax POST?
Can't print POST variable from AJAX using PHP
can anyone guide me in right direction. Thank you