jquery$.parseXML无法从php字符串解析XML?
不知何故,当我试图从php字符串解析xml时,javascript中不断出现错误,我的代码如下: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 = 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。使用双引号?