我有两种形式,我验证并发送到同一页面,之后我需要,对于每个请求,我的响应与 php 文件不同。所以我的问题,我如何找到不同的 ajax 请求。我试过
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
但这适用于所有请求..
$(document).ready(function(){
$("#form1").validate({
debug: false,
rules: {
passwordid:"required",
username:"required",
password_again :"required",
password_again:{
equalTo: "#passwordid"
},
email: {
required: true,
email: true
}
},
messages: {
email: "Please enter your valid email address.",
username: "Please enter your username",
passwordid:"Enter Password",
password_again:"Please enter the same value",
},
submitHandler: function(form) {
$.ajax
({
type: "POST",
url: "action.php",
data: $('#form1').serialize(),
cache: false,
success: function(html)
{
$(".result").prepend(html);
}
});
}
});
$("#form2").validate({
debug: false,
rules: {
datepicker:"required",
hourid1:"required",
minuteid1:"required",
dhour:"required",
dminute:"required",
},
messages: {
datepicker:"Please enter your date",
hourid1: "Enter your time",
minuteid1:"Enter your time",
dhour:"Enter your duration",
dminute:"Enter your duration",
},
submitHandler: function(form) {
$.ajax
({
type: "POST",
url: "action.php",
data: $('#form2').serialize(),
cache: false,
success: function(html)
{
$(".result1").prepend(html);
}
});
}
});
});
我只需要一种简单的方法来识别我的ajax请求..任何帮助表示赞赏..提前致谢..如果这发生在一个愚蠢的问题上,我很抱歉......