A video tutorial showing you how to post JavaScript variables to PHP using AJAX
http://www.abell12.com
http://www.twitter.com/abell12youtube
http://www.facebook.com/pages/Abell12/265102633605437
Original source
A video tutorial showing you how to post JavaScript variables to PHP using AJAX
http://www.abell12.com
http://www.twitter.com/abell12youtube
http://www.facebook.com/pages/Abell12/265102633605437
Original source
20 responses to “JavaScript: Post to PHP (AJAX)”
Thanks man!
is it possible to send html arrays to php?
why its not working in newer versions of php
its JQUERY :'( not vanilla javascript!!! CHEATER
THANK YOU BRO!!!!!!!!!! THAAAAAAANKS!!!!!!!!!!!!!!!! 🙂
Nice work
but my content which is echoed is not shown or sometimes it just shown and vanishes please help me out
where did you declare the variable data?
Great video!!
I have a question, if I wanted to use this on a link instead of a button like the video, how could I get it to work? I've tried embedding the $.post function from your video into a click function for the link so far and it works by getting the elementID (a unique id for that anchor tag) and storing it in a variable. This part works. However, getting it to post to my php file thus far has been unsuccessful . It's for a project in college so any help at all would be appreciated!!
How can I attache this form to an array?
Thanks for this
Nice video
This is great if you want to use JQuery, I just don't.
saved my day ! very helpful thank you
you are a legend dude
its jQuery Gandalf!
very good, tks
Hi even if I copy your code 100% except for <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
It does nothing any advice?
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<form>
<input type="text" id="name" placeholder="name">
<input type="text" id="age" placeholder="age">
<input type="button" value="submit" onclick="post();">
</form>
<div id="result"></div>
<script type="text/javascript">
function post()
{
var name =$('#name').val();
var age =$('#age').val();
alert('name s = ' + name);
$.post('validate.php',{postname:name,postage:age},
funtion(data)
{
if(data=="1")
{
$('#result').html('You are over 18');
}
if(data=="0")
{
$('#result').html('You are under 18');
}
});
}
</script>
//validate.php
<?php
$name = $_POST['postname'];
$age = $_POST['postage'];
if ($age >=18)
{
echo "1";
}
else
{
echo "0";
}
?>
could you please provide source code
Are you coding on a river?
can I get js variable to php without submitting?