This code is not working properly. What i want is just send the variable $something
to the page.php
What is the correct way to do this ? :
First of all, I think you have mistakenly mixed PHP and JavaScript. In your code the line:
$something = "text";
may be understood in two ways. If this is the whole code you have, then you are actually initializing JavaScript variable called $something
. Later in the code you are trying to use the value of PHP variable called $something
.
What you need to do is to change the code into (assuming you want to pass variable from PHP):
<?php $something = "text"; ?>
$.ajax({
url: 'page.php',
type: 'post',
dataType: 'html',
data: '<? php $something; ?>',
success: function (data) {
$('#total').load('xxx.php');
}
});
or into (assuming you want JS variable):
var $something = 'text';
$.ajax({
url: 'page.php',
type: 'post',
dataType: 'html',
data: $something,
success: function (data) {
$('#total').load('xxx.php');
}
});
myFile.php:
<?php $something = 'text'; ?>
<script>
$.ajax({
url: "page.php",
type: "post",
dataType: "html",
data: '<?php echo $something; ?>',
success: function (data) {
$('#total').load('xxx.php');
}
});
</script>