cannot get ajax sucess function to pull the response data from php script.
Hi Everyone,
Simple question. I have a very very simple script to test ajax with. However I cannot get the success function to fire even though debuger shows that the response is available. Code below
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script language="javascript1.5" src="../js/jquery-1.11.1.js"></script>
<script language="javascript1.5">
function getTest(t) {
$.ajax({
url:"test.php",
data:{p: t},
dataType:"dataString",
type:"POST",
error: function() {
alert('crap!');
},
success: function(data) {
alert('data: ' + data);
$("#t").html(data);
}
});
};
</script>
</head>
<body>
<a onClick="getTest('test');" name="t">click me</a>
<div id="t"></div>
</body>
</html>
PHP code
<?php
if (isset($_POST['p'])){
echo 'Wow we have a response';
}
?>
script goes to the error function though it does get a response from the server with the expected results.
Not sure what I am missing here.