Alfraganus Posted August 18, 2015 Share Posted August 18, 2015 I was creating a small html and ajax combination funchtion, but ajax one is not working, when I am clicking the button, it should show me "hello world" string, however, function is not working, let me show my codes if I've done something wrong: <!DOCTYPE html> <html> <head> <title>ajax tuturial</title> <script scr="jquery.js"></script> <script> $(document).ready(function() { $("#sub").click (function() { $.post("test.php", function(data) { $("#result").html(data); }); }); }); </script> </head> <body> <div id="box"> <h2>new user register</h2> <input type="text" name="name" id="name" placeholder="enter your name"><br> <input type="submit" name="sub" value="submit" id="sub" /> <div id="result"> </div> </div> </body> </html> Link to comment Share on other sites More sharing options...
dauruk0512 Posted August 19, 2015 Share Posted August 19, 2015 <html><head><script src="http://code.jquery.com/jquery-2.1.4.js"></script><script> $(document).ready(function(){ $("#sub").click(function(){ var name = $("#name").val(); $.post('test.php',{ name:name },function(data){ $("#result").html(data); }); }); }); </script> </head> <body> <div id="box"> <h2>new user register</h2> <input type="text" name="name" id="name" placeholder="enter your name"><br> <input type="submit" name="sub" value="submit" id="sub" /><div id="result"> </div> </div> </body></html> then here is tes.php handle your post from index <?php echo $_POST['name']; ?> this is my way to solved yours, thanks 2 Link to comment Share on other sites More sharing options...
Alfraganus Posted August 19, 2015 Author Share Posted August 19, 2015 it worked, thanks you for your help, but what was the mistake? how could you manage it? Link to comment Share on other sites More sharing options...
dauruk0512 Posted August 20, 2015 Share Posted August 20, 2015 You didn't save your input name in variable. Your jquery is exist in your directory ? just compare yours with mine, good luck ! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now