'Unterminated regular expression literal' error while parsing XML data from a foreign domain by javaScript

女生的网名这么多〃 提交于 2020-01-16 07:19:09

问题


So I'm starting this thread to fix a (likely syntax) error I encountered while implementing the answer by steven.yang at this question.

I tried his suggestion here, but got the error:

Unterminated regular expression literal.

This looks like a minor thing to fix, but I myself am not sure how to fix it.

Thanks!

update

since using jsonp makes it access the xml file, would it be possible to tell the computer to ignore any errors, just return the content of the <webcite_url> tags?


回答1:


This php script will copy an external xml file to your local server. This will then allow you to parse that file instead.

I'm just working on a project that involves working with external data- you'll just need to execute this script when you want to update the xml file.

<?php
/**
* Initialize the cURL session
*/
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL, 'http://*path/to/external.xml*');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec ($ch);
curl_close ($ch);
if (@simplexml_load_string($xml)) {
    /**
    * Create a new file
    */
    $fp = fopen('*desiredfilename*.xml', 'w');
    fwrite($fp, $xml);
    fclose($fp);
}

?>



回答2:


The URL you're requesting isn't JSONP.

You get a syntax error when the browser tries to parse the XML response as Javascript.



来源:https://stackoverflow.com/questions/9356109/unterminated-regular-expression-literal-error-while-parsing-xml-data-from-a-fo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!