Jump to content

Texan78

Members
  • Content count

    272
  • Joined

  • Last visited

Community Reputation

2 Neutral

About Texan78

  • Rank
    Advanced Member
  1. Texan78

    Event binding with dynamic ID's

    When the script inc/alertsUS.php script is updated by the AJAX script there is an icon on the divs which in this case is a link to open a modal for more information. When the page is first loaded the links work fine and open the modals and the modals are populated with the correct information. BUT if there is new data that means a new div is generated in which case that link is not clickable. If I refresh the page then I can click the link. After doing research I discovered this is because the click event needs to be binded. So that is what I am trying to accomplish is so that when new data is populated with a new link that link is clickable without having to refresh the page manually.
  2. Texan78

    Event binding with dynamic ID's

    The content of #svrAlertsUS isn't what is getting injected into the modal. That just displays the page from inc/alertsUS.php in DIVs where I want the data outputted. That ID is the AJAX ID to that script if that makes sense and I am explaining it correctly. I have tried this but it's not working ether function auto_load(){ //National Warning & Watches Settings $.ajax({ url: "inc/alertsUS.php", cache: false, success: function(data){ $("#svrAlertsUS").html(data); } }); } $(document).ready(function(){ $('#svrAlertsTX').on('click', 'a', function () { $('.alert-modal').html(data); }); auto_load(); //Call auto_load() function when DOM is Ready }); //Refresh auto_load() function after 10000 milliseconds setInterval(auto_load,55000); How would I use that "var id = e.target.id" option?
  3. Texan78

    Event binding with dynamic ID's

    Yeah that makes sense and something I had thought about if I needed to go higher up. I had tried that but I didn't go outside the script being called by the AJAX. I just wrapped the entire modal in a new ID etc. So as you can see from my first post the AJAX calls an ID svrAlertsUS. On the page which the divs with the data being displayed it is in a container like so... <div id="alertsUS-expanded" class="collapse"> <div id="svrAlertsUS"></div> </div> So since the ID svrAlertsUS is the container would this work? $('#alertsUS-expanded').on('click', 'a', function () { $('.alert-modal').html(data); }); Should this be in the script with the AJAX calls or somewhere else? The reason I am not using the actual event names with "var id = this.id;" is because I don't know the ID as they are dynamic and generated from a JSON file from an API. So when I parse the JSON I have to insert the PHP variable for the ID to use so the modals and links are unique. Would that suggestion still work even though the ID's are generated dynamically? -Thanks
  4. I have some some divs which are dynamically created from a PHP script and displayed to a page via AJAX so the data in the divs are updated/refreshed when new data is present in a JSON file. These divs have a link on it to open a modal. When the page first loads the links work great. When the script updates the PHP file and there is new data to display on the page the links for the new data do not work. Therefore I have found out I need to bind the event via .on(click). Here is my problem I am running into since they are not static IDs to bind to. The IDs are dynamically produced based on the ID from a JSON file that is created from a 3rd party API. Here is a snippet of the code that creates the link. $AlertData .= "<div class='alert__view' id='eventID'>\n"; $AlertData .= "<a href='#{$eventID}' data-toggle='modal' data-backdrop='false' data-target='#{$eventID}'><i class='fa fa-info-circle'></i></a>\n"; $AlertData .= "</div>\n"; $eventID is the ID for the link as shown in the code above and is also the ID for the modal which it is linked to in order to open dynamic and unique modals for the associated data. So what I have tried to do is this since it doesn't have to be binded to the exact ID I can bind it to the parent ID or class. In this case alert__view for the link as you see above and for the modal using the class .alert-modal instead of the ID since it is dynamic is uses $eventID like the link does. $('.alert__view').on('click', 'a', function () { $('.alert-modal').html(data); }); So I have included this snippet in my AJAX file for updating/refreshing the PHP script like as follows. function auto_load(){ //National Warning & Watches Settings $.ajax({ url: "inc/alertsUS.php", cache: false, success: function(data){ $("#svrAlertsUS").html(data); } }); } $(document).ready(function(){ $('.alert__view').on('click', 'a', function () { $('.alert-modal').html(data); }); auto_load(); //Call auto_load() function when DOM is Ready }); //Refresh auto_load() function after 10000 milliseconds setInterval(auto_load,55000); Unfortunately this is not working. Am I including the binding wrong? Should I put it in the PHP script or should it be merged into the AJAX call somehow? Or do I have this just completely wrong. -Thanks down votefavorite
  5. Texan78

    Using cURL to return API XML response

    Manual shows nothing about the missing echo statement which is what it was. Also the data I was trying to get a response wasn't available in cap+xml only in atom+xml and JSON. So I will be re-writing the scripts to use JSON which is better now that JSON is available now.
  6. Forgive me if this is simple. My research has brought me to a halt at the moment. I am trying to use cURL to get the response of an API in XML. This is the URL of the API: https://api.weather.gov/alerts/active/region/land By default it returns in JSON. Which I know, I should just use the JSON response but, there is a reason I need it in XML as it will seamlessly integrate into my current code until I can rewrite it for JSON. This is the documentation for the API. Under the API Reference tab is states I just need to change the request header to application/cap+xml. But I am not getting anything back. Just a blank white page. https://alerts-v2.weather.gov/documentation Here is my current code I am using to call the API but I get no response or anything. What am I missing? <?php $headers[] = 'Connection: Keep-Alive'; $headers[] = 'Content-Type: application/cap+xml;charset=utf-8'; $headers[] = 'Accept: application/cap+xml'; $userAgent = 'php'; $url = 'https://api.weather.gov/alerts/active/region/land'; $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, $url); curl_setopt($cURL, CURLOPT_HTTPHEADER, $headers); curl_setopt($cURL, CURLOPT_USERAGENT, $userAgent); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($cURL, CURLOPT_HTTPGET, true); $result = curl_exec($cURL); curl_close($cURL); ?>
  7. Hello, It's been awhile since I have had to do this and I can't find any of my old code snippets. So having to go from memory. Just trying to start small and add to this. NWS is now has a JSON API where before they had XML/RSS. So I am trying to update or really create new scripts to use this new API before they take down the old method and my site is broke. I have not see this kind of JSON format before so I am a little lost. How would I go about pulling the Event, Sender and Description from the below example? { "@context": [ "https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld", { "wx": "https://api.weather.gov/ontology#", "@vocab": "https://api.weather.gov/ontology#" } ], "type": "FeatureCollection", "features": [ { "id": "https://api.weather.gov/alerts/NWS-IDP-PROD-2466813-2306361", "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [ -104.05, 38.88 ], [ -104.06, 38.86 ], [ -104.6, 38.71 ], [ -104.9, 38.87 ], [ -104.83, 38.98 ], [ -104.39, 39.03 ], [ -104.05, 38.88 ] ] ] }, "properties": { "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-2466813-2306361", "@type": "wx:Alert", "id": "NWS-IDP-PROD-2466813-2306361", "areaDesc": "El Paso", "geocode": { "UGC": [ "COC041" ], "SAME": [ "008041" ] }, "references": [ "https://api.weather.gov/alerts/NWS-IDP-PROD-2466797-2306350" ], "sent": "2017-07-26T21:22:38+00:00", "effective": "2017-07-26T21:22:38+00:00", "onset": "2017-07-26T21:22:00+00:00", "expires": "2017-07-26T22:00:00+00:00", "ends": "2017-07-26T22:00:00+00:00", "status": "Actual", "messageType": "Update", "category": "Met", "severity": "Severe", "certainty": "Observed", "urgency": "Immediate", "event": "Severe Thunderstorm Warning", "sender": "NWS Pueblo CO", "headline": "Severe Thunderstorm Warning issued July 26 at 3:22PM MDT expiring July 26 at 4:00PM MDT by NWS Pueblo CO", "description": "At 322 PM MDT, a severe thunderstorm was located over northern\nColorado Springs, moving east at 10 mph.\n\nHAZARD...60 mph wind gusts and quarter size hail.\n\nSOURCE...Radar indicated.\n\nIMPACT...Hail damage to vehicles is expected. Expect wind damage to\nroofs, siding, and trees.\n\nVery heavy rain is also occurring with this storm.\n\nLocations impacted include...\nColorado Springs, Air Force Academy, Yoder, Ellicott, Schriever AFB,\nPeterson AFB, Falcon, Cimarron Hills and Security-Widefield.", "instruction": "For your protection move to an interior room on the lowest floor of a\nbuilding.", "response": "Shelter", "parameters": { "eventMotionDescription": [ "2017-07-26T21:22:00.000-06:00...storm...278DEG...11KT...38.94,-104.75" ], "hailSize": [ "1.00" ], "windGust": [ 60 ], "NWSheadline": [ "A SEVERE THUNDERSTORM WARNING REMAINS IN EFFECT UNTIL 400 PM MDT FOR CENTRAL EL PASO COUNTY" ], "VTEC": [ "/O.CON.KPUB.SV.W.0172.000000T0000Z-170726T2200Z/" ], "EAS-ORG": [ "WXR" ], "PIL": [ "PUBSVSPUB" ], "BLOCKCHANNEL": [ "CMAS", "EAS", "NWEM" ], "eventEndingTime": [ "2017-07-26T22:00:00Z" ] } } }, I have tried this just trying to pull the sender data but no luck... <?php $headers[] = 'Connection: Keep-Alive'; $headers[] = 'Content-Type: application/json;charset=utf-8'; $headers[] = 'Accept: application/json'; $userAgent = 'php'; $url = 'https://api.weather.gov/alerts/active?region_type=land'; $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, $url); curl_setopt($cURL, CURLOPT_HTTPHEADER, $headers); curl_setopt($cURL, CURLOPT_USERAGENT, $userAgent); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($cURL, CURLOPT_HTTPGET, true); $result = curl_exec($cURL); curl_close($cURL); /* Lets get and parse the data and create the variables */ $obj = json_decode($result); $issued_by = $obj->sender; ?>
  8. Texan78

    Order filtered values from XML

    Anyone?
  9. Texan78

    Order filtered values from XML

    Thanks, I am not worried about the other right now. Each their own. Main focus is getting these sorted by priority and I have no idea how to do this and cannot find any examples. I have even been willing to PAY someone to do this since last November for what is probably less than 5 mins of work but can't find anyone. Is what I am asking that difficult? I didn't think it was that difficult, I see sites doing it all the time everyday. I have already tried the array approach and got shot down on here with it and could never get it working.
  10. Hello, I have been struggling with this for months and please be gentle as I am not a coder. Just a hobbyist trying to build a site for my brand. I know just enough to try to do what I need to do so I certainly do not know the best logic. I have been search for months and months for how to do this. I have three events I need to show in a certain order when they display. 1.) Tornado Warning 2.) Severe Thunderstorm Warning 3.) Flash Flood Warning I have them filtered but I am probably not using the best logic for this approach. Is there anyone who could offer some assistance and help me out with ordering these by severity as I have posted above so I can mark this little section as completed. -Thanks hugely!!! ini_set('display_errors','1'); ## Start Configurable data ## //Set message to display if there were not report $noStormMessage = 'There are currently no active severe weather alerts'; //Set path to data file #$data = "http://alerts.weather.gov/cap/".$zone.".php?x=0"; $data = "../xml/nat_warnings.xml"; ## End Configurable data ## // get path info & protect for cross-site scripting vulnerability $sri = ($_SERVER['REQUEST_URI']) ? str_replace('#SA', '', htmlspecialchars(strip_tags($_SERVER['REQUEST_URI']))) : ''; $error = false; //Set initial output to false $AlertData = false; $entries = simplexml_load_file($data); if(count($entries)): //Registering NameSpace $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom'); $result = $entries->xpath("//prefix:entry"); if(!$result){ $error = true; } foreach ($result as $entry): $updated = $entry->updated; if($updated == ''){ $error = true; } $Updated = date("D, M d, g:i a", strtotime($updated)); $summary = $entry->summary; if($summary == ''){ $error = true; } // Replaces all triple periods with single periods $summary = trim(str_replace('...', '.', $summary), '.') . '.'; //now capitalize every letter after a . ? and ! followed by space $Summary = preg_replace_callback('/([.!?*])\s*(\w)/', function ($matches) { return strtoupper($matches[1] . ' ' . $matches[2]); }, ucfirst(strtolower($summary))); $event = $entry->children("cap", true)->event; if ($event == ''){ $error = true; } $url = $entry->id; $updated = $entry->updated; $link = $entry->link; $effective = $entry->children("cap", true)->effective; $expires = $entry->children("cap", true)->expires; $updated = date("l M jS, g:i A", strtotime($updated)); $effectiveDate = date("l M jS, g:i A", strtotime($effective)); $expiresDate = date("D M jS, g:i A", strtotime($expires)); $status = $entry->children("cap", true)->status; $severity = $entry->children("cap", true)->severity; $urgency = $entry->children("cap", true)->urgency; $area = $entry->children("cap", true)->areaDesc; include ('alertColors.php'); // Let's assign the table some styles $divNoStorms = "padding:5px; width:45%; margin:auto; margin-top:5px; margin-bottom:5px"; // If no storms were in the source, set no storm message if($error) { $AlertData .= "<div style='{$divNoStorms}' class='alert alert-info' role='alert' data-toggle='tooltip' data-placement='top' title='There are currently no active severe weather alerts.'>\n"; $AlertData .= "{$noStormMessage}\n"; $AlertData .= "</div>\n"; } elseif ($event == 'Tornado Warning' || $event == 'Severe Thunderstorm Warning' || $event == 'Flash Flood Warning') { $AlertData .= "<div>\n"; $AlertData .= "<div id='{$alertID}' class='individualAlert'>\n"; $AlertData .= "<div class='text_alert'>\n"; $AlertData .= "<span class='title {$alertClass}'><i class='fa fa-exclamation-triangle severe-icon__tornado'></i>{$event}</span>\n"; $AlertData .= "<span class='state'>{$stateShort}</span>\n"; $AlertData .= "<span class='counties'>{$area}</span>\n"; $AlertData .= "<span class='expires'>Expires: {$expiresDate}</span>\n"; $AlertData .= "</div>\n"; $AlertData .= "<div class='alert__view'>\n"; $AlertData .= "<a href='{$url}'><span class='fa fa-eye'></span></a>\n"; $AlertData .= "</div>\n"; $AlertData .= "</div>\n"; } $AlertData .= "</div>\n"; endforeach; endif; echo $AlertData;
  11. Texan78

    Total number from XML values

    Ok let me try to explain what I am trying to do. The arrary you see is all the active alerts and how many of that alert is currently active. from the "../xml/nat_warnings.xml" There is a possibility of over 116+ events. This is why I created the arrary to only check the ones I want. In this case I just need to total number of alerts for "'Tornado Warning', 'Severe Thunderstorm Warning', 'Flash Flood Warning'" with the ability to add more as needed depending on the season. With the orginal code that filters what I want and gives me to total number of each alert. So what I am needing now is to take all those numbers and add them together in to one single value which I can call with a single variable. Reason for this is I am making a badge kind of like what you see on iPhones that gives the total number of alerts. So it will take all the alerts I want and add them all together into one single value. This is where I am stuck is just creating a single variable that will give me the total number of the select alerts I want. -Thanks
  12. Texan78

    Total number from XML values

    Hello, When I try what you suggested which is this. ini_set('display_errors','1'); ## Start Configurable data ## ##$data3 = "../xml/nat_warnings.xml"; ## End Configurable data ## $sri = htmlspecialchars('Tornado Warning', 'Severe Thunderstorm Warning', 'Flash Flood Warning', ENT_QUOTES); $xml = new SimpleXMLElement("../xml/nat_warnings.xml", 0, true); $xml->registerXPathNamespace("cap", "urn:oasis:names:tc:emergency:cap:1.1"); $count = count($xml->query("/feed/entry[cap:event = '{$sri}']")); print_r($count); Then I get this error. I much prefer SimpleXML but, there is a reason I am using DOM for this as there is something else I will be doing with this later once I get this sorted out.
  13. Hello, I am bit stuck and could use some assistance. I am know I need to probably use an array to filter out only the results I need but, the solutions I have tried have not been successful. What I am trying to do is get the total number of certain events within an XML file. I have got it to where it prints out all the events within the XML file but, this is where I am stuck. How to filter out only certain events that I want the value of then get a single total combined number of those chosen events. Here is the test link of what the output looks like now. http://stream.dfwstormforce.com/inc/alertsCount.php ini_set('display_errors','1'); ## Start Configurable data ## $data3 = "../xml/nat_warnings.xml"; ## End Configurable data ## // get path info & protect for cross-site scripting vulnerability $sri = ($_SERVER['REQUEST_URI']) ? str_replace('#SA', '', htmlspecialchars(strip_tags($_SERVER['REQUEST_URI']))) : ''; // Lets parse the feed $dom = new DOMDocument(); $dom->load($data3); $events = []; foreach ($dom->getElementsByTagNameNS("urn:oasis:names:tc:emergency:cap:1.1", "event") as $event) { $events[] = $event->nodeValue; } //$message = $event->nodeValue; //$alertValues = array('Tornado Warning', 'Severe Thunderstorm Warning', 'Flash Flood Warning', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory'); $counts = array_count_values($events);//lets count the results //$value = isset($counts['Tornado Warning', 'Severe Thunderstorm Warning', 'Flash Flood Warning', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory')]); print_r($counts); -Thanks
  14. Texan78

    Dynamic populating rows

    Always looking for something more significant and it was the easiest thing. -Thanks
  15. Texan78

    Dynamic populating rows

    Hello, I am looking for some assistance with something I done before but forgot and I can't find my code snippets from when I used this method in the past. If you reference the screenshot below you will see boxes going across. What I am trying to do is put each one on its own row but can't remember how it is done. I have tried putting a <tr> in the loop but that doesn't work which I have commented out below where I had it for example purposes. Could anyone offer some help with this? BTW I am using this with bootstrap and calling it into the HTML template with jQuery so it refreshes on its own with updated information. -Thanks // If no storms were in the source, set no storm message if($error) { $AlertData .= "<div style='{$divNoStorms}' class='alert alert-info' role='alert' data-toggle='tooltip' data-placement='top' title='There are currently no active severe weather alerts.'>\n"; $AlertData .= "{$noStormMessage}\n"; $AlertData .= "</div>\n"; } elseif ($event == 'Tornado Warning' || $event == 'Severe Thunderstorm Warning' || $event == 'Flash Flood Warning') { //$AlertData .= "<tr>\n"; $AlertData .= "<div class='col-md-3'>\n"; $AlertData .= "<div id='{$alertID}' class='individualAlert'>\n"; $AlertData .= "<div class='text_alert'>\n"; $AlertData .= "<span class='title {$alertClass}'><i class='fa fa-exclamation-triangle severe-icon__tornado'></i>{$event}</span>\n"; $AlertData .= "<span class='state'>{$stateShort}</span>\n"; $AlertData .= "<span class='counties'>{$area}</span>\n"; $AlertData .= "<span class='expires'>Expires: {$expiresDate}</span>\n"; $AlertData .= "</div>\n"; $AlertData .= "<div class='alert__view'>\n"; $AlertData .= "<span class='fa fa-eye'></span>\n"; $AlertData .= "</div>\n"; $AlertData .= "</div>\n"; } $AlertData .= "</div>\n"; //$AlertData .= "</tr>\n"; endforeach; endif; echo $AlertData;
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.