求助,js嵌套文件里面再嵌套一个php文件 为什么无效html 文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="plus/ajax/a.js"></script>
<title>无标题文档</title>
</head>
<body></body>
</html>a.js
document.write("<scri"+"pt type='text/javascript' src='b.php'></scr"+"ipt>"); b.php
<?
header("Content-Type: text/html; charset=UTF-8");
echo "alert('test');";
?>
jsphp

解决方案 »

  1.   

    LZ的例子是对的,php输出js是可行的。
    LZ先检查一下路径问题,看看直接访问b.php是否能看到输出的js代码。
    再有就是,b.php中,Content-Type的报头不能是text/html,改成text/javascript或者application/javascript,或许就好了。
      

  2.   

    php里面 做判断 
    再<? print_r(""<script></script>); ?>如果是前端 判断的话 就用<scrip type="text/javascript" src="xxx"></script> 引入吧
      

  3.   


    路径没有问题 我改成 application/javascript 或者text/javascript 都不行,
      

  4.   

    应该是路径的问题
    你的a.js和b.php是都在ajax目录中吧
    document.write()是向html文件中输出,所以src的路径要写成相对于html文件的路径
    document.write("<scri"+"pt type='text/javascript' src='plus/ajax/b.php'></scr"+"ipt>");