我有2个文件abc.php和xyz.php。当我在移动设备上打开时,它包括abc.php和桌面上的xyz.php。我在下面列出了这些文件,但它不起作用。欢迎任何建议。
<script>
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
<?php include ('abc.php');?>
} else {
<?php include ('xyz.php');?>
}
</script>
答案 0 :(得分:1)
PHP是服务器端语言。你不能这样加载。
所以请改用ajax。
<script>
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
var include = "abc.php";
} else {
var include = "xyz.php";
}
$.ajax({
url:"url to a function where you can include specified file",
type:"POST",
data:{file: include},
success: function(){
// you can get executed content of a file here.
}
});
</script>