Forum Discussion
JohnBarulich1
Qrew Cadet
Thanks again for the help, Dan!
In this snippet:
Why are we required to select BOTH 'record' and 'xml' in order to access those 3 elements, if those 3 elements are only a part of a record. If we are selecting two separate elements (in this case, record and xml) why doesn't this iterate through 'rid', 'name', and 'type' for both selections? It seems as though these selections are linked, but how? Aren't they distinct elements?
i.e. Why doesn't this work?:
Another question. In each record of the XML response I have a field [Event Time] that stores a time. But this time is simply a large numeric number. How do I convert this numeric number to a duration?
i.e. 1. numDifference = numericNum1 - numericNum2
2. convert numDifference to duration
Would this work?
In this snippet:
$("record", xml).each(function() {});
var rid = $("record_id_", this).text();
var name = $("function_name", this).text();
var type = $("result_type", this).text();
console.log(rid, name, type);
Why are we required to select BOTH 'record' and 'xml' in order to access those 3 elements, if those 3 elements are only a part of a record. If we are selecting two separate elements (in this case, record and xml) why doesn't this iterate through 'rid', 'name', and 'type' for both selections? It seems as though these selections are linked, but how? Aren't they distinct elements?
i.e. Why doesn't this work?:
$("record").each(function() { ... });
Another question. In each record of the XML response I have a field [Event Time] that stores a time. But this time is simply a large numeric number. How do I convert this numeric number to a duration?
i.e. 1. numDifference = numericNum1 - numericNum2
2. convert numDifference to duration
Would this work?
_anomDiebolt_
7 years agoQrew Elite
>Why are we required to select BOTH 'record' and 'xml'
The first argument is the selector which specifies what to look for - in this case <record> elements. The second argument is the context - in this case it is the XML document returned by the AJAX call. If you don't specify xml as the second argument it will default to the current document - namely the HTML page currently being displayed.
>i.e. Why doesn't this work?
>$("record").each(function() { ... });
Because without the xml as the second argument the the .each() method will be iterating of <record> elements in the current HTML page (there aren't any because <record> is not a recognized HTML tag). Again, specifying xml as the second argument tells jQuery to use the XML document returned by the AJAX call as the context.
>Another question. In each record of the XML response I have a field [Event Time] that stores a time. But this time is simply a large numeric number. How do I convert this numeric number to a duration?
In most programming languages time is represented as milliseconds since the start of the unix epoch (Midnight January 1, 1970). This code will get the milliseconds since the start of the unix epoch as an integer:
var ms = parseInt($("event_time", this).text(), 10);
But it isn't clear what the exact field type is for [Event Time].
The first argument is the selector which specifies what to look for - in this case <record> elements. The second argument is the context - in this case it is the XML document returned by the AJAX call. If you don't specify xml as the second argument it will default to the current document - namely the HTML page currently being displayed.
>i.e. Why doesn't this work?
>$("record").each(function() { ... });
Because without the xml as the second argument the the .each() method will be iterating of <record> elements in the current HTML page (there aren't any because <record> is not a recognized HTML tag). Again, specifying xml as the second argument tells jQuery to use the XML document returned by the AJAX call as the context.
>Another question. In each record of the XML response I have a field [Event Time] that stores a time. But this time is simply a large numeric number. How do I convert this numeric number to a duration?
In most programming languages time is represented as milliseconds since the start of the unix epoch (Midnight January 1, 1970). This code will get the milliseconds since the start of the unix epoch as an integer:
var ms = parseInt($("event_time", this).text(), 10);
But it isn't clear what the exact field type is for [Event Time].