Parsing the National Threat Level XML File with jQuery

By : Kerrick

I'm trying to use jQuery to parse the DHS Threat Level that they have in their XML file, but I can't seem to get it to work. I'm very new with Javascript and non-presentational jQuery, so I'm probably missing something obvious.

This is the XML file:

<?xml version="1.0" encoding="UTF-8" ?> 

This is the Javascript I've written:

$(document).ready(function() {
    	type     :	'GET',
    	url      :	'',
    	dataType :	'xml',
    	success  :	function parseThreatLevel(xml) {
    					var threatLevel = $(xml).find('threat_advisory').attr('condition');

Below is the HTML I'm trying to use. Thanks in advance for any help or advice!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="">
    <script type='text/javascript' src=''></script>
    <script type='text/javascript' src='lib/parseThreatLevel.js'></script>
    	<title>National Threat Level</title>
    	<div id='nationalThreatLevel'></div>
By : Kerrick

For security reasons, javascript has no access to other domains. To bypass this, you need to add a script on your server that does have access to other domains - often times called a proxy.

PHP is a great option for many web-developers. What you would do is post the website url you want to hit to your local PHP script, it will then request that page and return the contents of it to your jQuery script which you can then parse for the data you desire.

Non-SO Solutions:

Stackoverflow Archive:

By : Sampson

All of your code is correct, but the problem is that you are making a cross domain request. The only way this will work with JavaScript / jQuery is if you can find a JSONP provider. Well, that or you write your own server side (PHP/ASP/ColdFusion/Something) to retrieve the XML and provide a local copy to be able to retrieve the XML using JavaScript.

XML is case-sensitive, isn't it? You might try using THREAT_ADVISORY and CONDITION. That is,

var threatLevel = $(xml).find('THREAT_ADVISORY').attr('CONDITION');
By : Matt

This video can help you solving your question :)
By: admin