Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.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
jquery$.parseXML无法从php字符串解析XML?_Php_Javascript_Jquery_Xml - Fatal编程技术网

jquery$.parseXML无法从php字符串解析XML?

jquery$.parseXML无法从php字符串解析XML?,php,javascript,jquery,xml,Php,Javascript,Jquery,Xml,不知何故,当我试图从php字符串解析xml时,javascript中不断出现错误,我的代码如下: <?php $xml = simplexml_load_file('file.xml'); $products = $xml->xpath("/products/product[@model='".$model . "']"); $filtered_xml = $products[0]->asXML(); ?> <script> alert( $.parseX

不知何故,当我试图从php字符串解析xml时,javascript中不断出现错误,我的代码如下:

<?php
$xml = simplexml_load_file('file.xml');
$products = $xml->xpath("/products/product[@model='".$model . "']");
$filtered_xml = $products[0]->asXML();
?>

<script> 
alert( $.parseXML( '<?php echo $filtered_xml;?>'  ).find('name').text() );
</script>
xpath(“/products/product[@model='.$model.']”);
$filtered_xml=$products[0]->asXML();
?>
警报($.parseXML('').find('name').text());
echo$filtered\uxml
正在返回我正在查找的格式良好的xml,但javascript-
$中的某些内容。parseXML(“”)
正在导致错误。提前感谢您的帮助

$.parseXML()本身不返回jQuery对象。请看文档中的示例

在您的情况下正确使用更像:

  var xml= $.parseXML( '<?php echo $filtered_xml;?>') ;

   alert( $(xml).find('name').text() )
var xml=$.parseXML(“”);
警报($(xml).find('name').text())

您能指定您得到的错误吗?您能显示浏览器上呈现的标记吗?我打赌它不会执行php。使用双引号?