下面是我的代码,它总是让我返回true,所以我的行动已经提交。任何人都可以帮我解决这个问题。在得到ajax的响应后,即使我写了return false,它也会成立。
<?php
if(isset($_POST['submit'])){
die("lokesh");
}
?>
<html>
<head>
<script src="js/jquery-1.8.2.min.js"></script>
<script>
function checkjs(){
if(document.getElementById('a').value==""){
alert("insert a");
return false;
}
if(document.getElementById('b').value==""){
alert("insert b");
return false;
}
if(document.getElementById('c').value==""){
alert("insert c");
return false;
}
var companyname = document.getElementById('b').value;
var username = document.getElementById('c').value;
jQuery.ajax({
type: "POST",
dataType: "json",
url:'checkexisting.php',
data:{
companyname: companyname,username: username,
},
success:function(response) {
alert("response"+response);
return false;
}
});
}
</script>
</head>
<body>
<form action="#" method="post" name="form">
<input type="text" id="a">
<input type="text" id="b">
<input type="text" id="c">
<input type="submit" name="submit" onclick="return checkjs();">
</form>
</body>
</html>
以下代码适用于checkexisting.php
<?php
$companyname = $_REQUEST['companyname'];
$username = $_REQUEST['username'];
$response = $companyname.$username;
echo json_encode($response);
?>