Jump to content

HTML and AJAX problem


Alfraganus

Recommended Posts

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

<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

  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...