这里用到了jquery的ajax。
页面:
$.ajax({
type: 'post',
url: 'http://www.yourwebsite.com',
beforesend: function (xmlhttprequest) {
xmlhttprequest.setrequestheader(request_type,ajax);
},
data: 'test=test',
success: function(rs) {
alert('ok');
}
}
});
php代码:
echo isset( $_server['http_request_type']) && $_server['http_request_type'] == ajax ? it is ajax : it is not ajax.;
还有一种方法,js里面不用加beforesend里面的代码,直接在php里面作判断:
echo isset( $_server['http_x_requested_with']) && $_server['http_x_requested_with']==='xmlhttprequest' ? 'it is ajax' : 'it is not ajax';
ps:判断是否是flash提交数据
echo isset( $_server['http_user_agent']) && ( stripos( $_server['http_user_agent'],'shockwave')!== false || stripos( $_server['http_user_agent'],'flash')!== false) ? echo 'it is flash data' : 'it is not flash data';