'Unterminated Regular Expression Literal' Error While Parsing XML Data From A Foreign Domain By JavaScript
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 err
Solution 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);
}
?>
Solution 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.
Post a Comment for "'Unterminated Regular Expression Literal' Error While Parsing XML Data From A Foreign Domain By JavaScript"