I’m trying to pass some data to a PHP file using .post, but somewhere in the process, the value of the string I’m passing is lost and I’m receiving NULL.
Here’s the script:
<script type="text/javascript">
$("select").change(function () {
var tmp = "";
$("select option:selected").each(function () {
tmp = $(this).text();
});
$(".title").text(tmp);
$.ajax({
url:"php/description.php",
type:"POST",
data: { major:tmp },
success: function(result) {
alert(result);
}
});
});
</script>
And the simple PHP file I was testing it with.
<?php
$major = empty($_POST['tmp']);
echo $major;
?>
It’s being called when the user clicks a new option/item in a select list. The top of the script works correctly (simply getting the value of what they clicked and putting it somewhere on the page), but the post method does not work. It’s alerting NULL. I can’t find the problem.
seems like it should be