I try to send a variable using jquery and ajax to php script. Then I want to use that variable in creating a file name but it fails. The file name is always “0” and does not locate at the dir “redirect”.
Here is the code:
Ajax:
var pageName=$('#movie').val();
$.ajax({
type: "POST",
url: "phpstuff.php",
data: { pageName: 'pageName'},
cache: false,
success: function()
{
alert(pageName);
}
});
the “pageName” variable gets the value from an input box with an id “movie”
The php file
function createPage ($newPage){
$file=fopen("redirect/"+$newPage+".php","w") or exit("Fail to create the page");
$data = "some text I want to be in a file";
fwrite ($file, $data);
fclose($file);
}
$newPage = $_POST["pageName"];
createPage($newPage);
I have searched the net for hours and still can’t fix the problem.
String concatenation should be done with
.: