[英]how to include php file in javascript function?
我有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>
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.