JavaScript: Post to PHP (AJAX)
wie Sie tun, machen, Film, Beispiel
11m 29sLänge
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
Kommentare
-
So i would recommend using json enode instead of just echoing 1 Or 0
-
Great help, thanks !
-
I replaced the source to <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>but still not working. can anybody help
-
what if the script is not inside div tag?
then what should i use instead of $('#result') -
i wanna know if the page has reload or not?
-
you are awesome, love you so muchhhhhh
-
Nice, thk you...
-
for beginners who watch this vid. replace his code on the line 6: <script type="text/javascript" src="jquery.js"></script>
with this one: <script src="//code.jquery.com/jquery-1.12.0.min.js"></script> -
nice one
-
Made my day. Great tutorial, well explained. God bless :)
-
How do if you want to call a PHP function within a class?
-
I downloaded the jquery-1.12.1.min.js file then added the javascript you show in the tutorial to the bottom of this file, then post the source in the html <head>. It works fine, but I'm curious if this is the "correct" or "standard" way to do it?
Great tutorial by the way... -
Woooooow. Life Saver! Thank you!
-
You should name your video "jQuery: Post to PHP (AJAX)" if you're going to use jQuery. Some of us are trying to learn how to do it the hard way first...
-
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Post to PHP Tutorial</title>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<form>
<input type="text" id="name" placeholder="Enter Your Name..." /><br />
<input type="text" id="age" placeholder="Enter Your age..." /><br />
<input type="button" value="Submit" onclick="post();">
</form>
<div id="result"></div>
<script type="text/javascript">
function post()
{
//alert("working");
var name = $('#name').val();
var age = $('#age').val();
$.post('validate.php',{postname:name,postage:age},
function(data){
$('#result').html(data);
});
}
</script>
</body>
</html> -
Very nice. Finally some web-prog. tutorial which actually works. Just one question: if I want to echo on PHP side using echo so that it does not go back to javascript, how can I do it? I mean I just want to do echo normally in php file (so that the echo prints stuff on html page directly.... now it goes back to javasctip data and we do it there)? Also, if the javascript is in php file can I have all this code in php file or the php with if() must be a separate file? Can all this code be in one php file? I mean I do not want PHP to return back to javascript.... as I want to continue building the website on PHP side (like create a div on PHP side using the values got from javascript)?
-
Hey thanks for your tutorial I'm new at programming and I have a website that is php but I'm using JavaScript for programming my game that I want add to my site is this the way to go about doing it?
-
Nice work here. I understood everything quickly.
-
Great Job! Greetings from Poland! Thank You very much!
-
This one isn't working for me. Maybe you need to clear up exactly where you get the jquery file from. I'll use something else instead now.