Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ajax文件中同时执行php和javascript_Javascript_Jquery_Ajax - Fatal编程技术网

在ajax文件中同时执行php和javascript

在ajax文件中同时执行php和javascript,javascript,jquery,ajax,Javascript,Jquery,Ajax,我需要ajax在后台运行php和javascript脚本 $.ajax("j_update.php"); 然后:j_update.php: //-> Get an XML file $xmldata = simplexml_load_file('datafile.xml'); //->Look through foreach($xmldata->user as $user) { echo " <script type='text/javasc

我需要ajax在后台运行php和javascript脚本

$.ajax("j_update.php");
然后:j_update.php:

//-> Get an XML file
$xmldata = simplexml_load_file('datafile.xml');

//->Look through
foreach($xmldata->user as $user) {

    echo "
        <script type='text/javascript'>
        animateOther(".$user->ip.", ".$user->left.", ".$user->top.");
        spectrumOther(".$user->ip.");
        </script>";

}
/->获取一个XML文件
$xmldata=simplexml_load_文件('datafile.xml');
//->看穿
foreach($xmldata->user as$user){
回声“
animateOther(“.$user->ip.”、“$user->left.”、“$user->top.”);
spectrumOther(“.$user->ip”);
";
}
但是(正如我所预料的)这是不可能的,javascript不会被执行。我不确定正确的解决方法是什么。。。有什么想法吗

感谢而不是
$.ajax(“j_update.php”)
,使用
$.getScript(“j_update.php”)
并清除php文件中的
打开/关闭标记。还记得添加
标题(“内容类型:application/javascript”)位于php脚本的最顶端。

使用而不是$.ajax()来确保JavaScript运行