由于某些原因,使用ajax传递参数对我来说是一个真正的问题。我检查了有关参数的所有问题,并发现以下是传递参数的正确方法:
var username = $("#email_0000").val(),
password = $("#password_0000").val(),
func = 'emailexists',
bValid = true;
$.ajax({
type: "GET",
url: "php/ajax.php",
data: {
func:func,
email:username
},
success: function(data) {
alert(data);
}
});
以下是我的php代码:
<?php
$func = $_REQUEST['func'];
echo var_dump($_GET);
switch($func) {
case 'emailexists':
$email = $_REQUEST['email'];
echo 'Email address is='.$email;
break;
default:
return false;
break;
}
警告显示以下内容:
array(1){
["func"]=>
string(11)"emailexists"
}
Email address is=
我知道我做错了什么,但如果有人有线索我会很感激。我错过了“head”标签中的内容:
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="expires" content="1">
<!--Stylesheets-->
<link rel="stylesheet" href="css/jquery-ui.css">
<link rel="stylesheet" href="css/dhaStyle.css">
<!--JavaScripts -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
<script src="js/vendor/jquery.simplemodal.1.4.4.min.js"></script>
<script src="js/DHA_forms.js"></script>
提前感谢您的帮助,问候,Rich