我已经在这里读了很多问题,并尝试了几个教程,但不知何故,它仍然不工作,无论我试图修复。
这是我的HTML代码(/login.php)
<form action="func/login.php" method="post" name="login">
User: <input type="text" name="username" />
Password: <input type="password" name="password" id="password"/>
<img id="captcha" src="securimage/securimage_show.php" alt="CAPTCHA Image" />
<input type="text" name="captcha_code" size="10" maxlength="6" />
<a href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">[ Different Image ]</a>'
<input type="submit" value="Login" />
</form>
这里是我的JS (/JS/forms.js)
$(document).ready(function (){
$( "form[name='login']" ).submit(function( event ) {
$.ajax({
url: '../func/check_captcha.php',
data: {cc: $( "input[name='captcha_code']" ).val()},
dataType: json,
type: 'post',
success: function(data) {
if(data=="true") {
return true;
}
if (data=="false") {
event.preventDefault();
return false;
}
}
});
});
});
最后是PHP (/func/check_capcha . PHP)
<?php
require_once '../securimage/securimage.php';
$securimage = new Securimage();
if ($securimage->check($_POST['cc']) == false) {
$return = "false";
}
else {
$return = "true";
}
die(json_encode($return));
?>
有谁能看到主要的错误吗?
找到问题了…像往常一样,在数小时的编程和绞尽脑汁后,你会失去一些东西:
dataType: json,
应该dataType: "json",
至少到目前为止,这似乎解开了这个谜