我对php开发非常陌生。在应用程序I中,我有一个home.php页面,用户需要在其中输入安全代码并提交。如果输入的安全代码是正确的,那么应该向用户隐藏这两个分区( div是窗口和安全性),安全卡验证是使用securityValidation.class.php.进行的。validateSecuiryCode.类包含一个方法调用securityValidation.class.php它接受代码并检查数据库中的有效性,如果退出,则发送1其他0。
如果验证是正确的,可以帮助我隐藏在html部分的两个部门提交。非常感谢!
发布于 2011-10-12 06:28:30
如果您希望在ajax中有一个请求,它会在哪里请求securityValidation.class.php?我总是这样做。我创建了一个名为ajax.php的文件,然后添加数据库连接文件,如果存在函数文件的话。然后在$_GET的帮助下,我做了一个明智的选择。我给你举个例子!
//The ajax.php
<?php
include('conn.php');
include('functions.php');
if($_GET['a']) //My alias in the url
{
switch($_GET['a'])
{
case 'validateSecuiryCode':
//Include or anything what you want to do... Do make a return that only echo 1 or 0.
break;
}
}
?>这是请求ajax.php?a=validateSecuiryCode&code=1234141431
//The jQuery request to ajax.php
$(document).ready(function(){ //The DOM
$('#submit').click(function(){
var theCodeVal = $('#the_input_for_the_valid_code').val();
$.get('ajax.php',{"a":"validateSecuiryCode","code":theCodeVal},function(result){
if(result==1)
{
//The thing if validate code is right
}
else
{
//The thing if not valid code
}
});
});
});这是一个简化的示例,如何向php-函数发出ajax请求,然后显示返回,或者运行特定的js-函数。
https://stackoverflow.com/questions/7728668
复制相似问题