I am creating a site where the user fills out a form, has that data sent to a php script and display result in a div and have been struggling to complete it for a while now. Below is the code i have created:
the button activates this function:
function callFunc()
{
var testVar = "Example 01";
$.ajax(
{
url: "public/includes/userCreate.php",
type: "POST",
data: testVar,
success: function(html)
{
$('#web_Content').html(html);
}
});
};
The PHP file is this:
<?php
$test = $_POST['testVar'];
echo $test;
?>
For some reason though i doesnt work. I mean it doesnt inject the value of the echo command into the div, If however i take out the variable data from the PHP and just have it echo a simple element, it does work and injects the echo value into the div, Below is the code that will run:
<?php
$test = $_POST['testVar'];
echo "<h3>User ???? Created.</h3>";
?>
I think it is because i am not sending data correctly, Could anyone tell me the correct way to send the data to the PHP script and also, how to send more than one variable?
data: testVar.serialize(),?