mattcashatt
asked on
Consuming XML data from Wikipedia API with Javascript
I am struggling with something that I thought would be simple:
I can pull xml data from wikipedia like so (using "Paris Hilton" as an example):
http://en.wikipedia.org/w/api.php?action=opensearch&search=paris%20hilton&format=xml&limit=1
However, I can't seem to consume this xml via standard AJAX functions (please see attached).
The attached HTML has javascript that should simply show an alert modal with the responseText. This works when I use local xml files, but not for the wikipedia data.
Any help would be greatly appreciated.
Thanks!
Matt
XMLJavascript.txt
I can pull xml data from wikipedia like so (using "Paris Hilton" as an example):
http://en.wikipedia.org/w/api.php?action=opensearch&search=paris%20hilton&format=xml&limit=1
However, I can't seem to consume this xml via standard AJAX functions (please see attached).
The attached HTML has javascript that should simply show an alert modal with the responseText. This works when I use local xml files, but not for the wikipedia data.
Any help would be greatly appreciated.
Thanks!
Matt
XMLJavascript.txt
ASKER
HainKurt, can you please tell me what browser you are using? I only get a blank alert and I am using the same file.
Thanks,
Matt
Thanks,
Matt
Hello mattcashatt,
Me too on Chrome, blank alert.
Have a look to this article : http://en.wikipedia.org/wiki/User:Yurik/Query_API/User_Manual#JavaScript
Regards.
Me too on Chrome, blank alert.
Have a look to this article : http://en.wikipedia.org/wiki/User:Yurik/Query_API/User_Manual#JavaScript
Regards.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to hielo. The solution makes sense, however it is still not implementing correctly for me. I took Option B (the fetchFile Method), but the responseText comes back as this the code attached.
All I want to do is have access to XML generated by wikipedia based on a name like, "Albert Einstein".
I can "see" the XML by going to a link such as:
http://en.wikipedia.org/w/api.php?action=opensearch&search=albert%20einstein&format=xml&limit=1
But I can't seem to access it programmatically with javascript. I would REALLY appreciate a working example, like some code that would pass the name (Albert Einstein) and then alert the Wikipedia Summary, all via AJAX.
This seems like it shouldn't be so hard. Am I missing something obvious? Thanks!
All I want to do is have access to XML generated by wikipedia based on a name like, "Albert Einstein".
I can "see" the XML by going to a link such as:
http://en.wikipedia.org/w/api.php?action=opensearch&search=albert%20einstein&format=xml&limit=1
But I can't seem to access it programmatically with javascript. I would REALLY appreciate a working example, like some code that would pass the name (Albert Einstein) and then alert the Wikipedia Summary, all via AJAX.
This seems like it shouldn't be so hard. Am I missing something obvious? Thanks!
<?php
//fetchFile.php
echo file_get_contents('http://en.wikipedia.org/w/api.php?action=opensearch&format=xml&limit=1&search=' . urlencode($_GET['search']) );
?>
i run the file you attached and I got alert with xml inside...