whspider
asked on
how to pass values to a php file using ajax and jquery
Hi,
i needto pass a value to a php file. i tried doin so using $.ajax and $.post..but both did not work out...can u help me out as to where am makin mistake
i needto pass a value to a php file. i tried doin so using $.ajax and $.post..but both did not work out...can u help me out as to where am makin mistake
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Classic Example</title>
<script type="text/javascript" src="jquery.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function()
{
$('form#sub').submit(function(){
var MyJavascriptVariable = 'Kate Winslet';
// $.post("ajax.php",{js: MyJavascriptVariable});
$.ajax({
type: "POST",
url: "ajax.php",
data: "items="+MyJavascriptVariable,
success: function(data){
alert("hi");
});
});
});
</script>
</head>
<body>
<form id="sub" action="" method="post">
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.