So I am well aware that I have another post talking about this file, but as the problem on there seemed solved, I wanted to post a new thread. Anyway, I am having a new issue (which is technically the last thing I need done in order to officially be finished).
(yes this is in the other thread, sorry if this bothers someone, but needed an answer to this so I can be done.)
So now I am having trouble getting the rankings. I did get the names to populate the list and got the meaning to display and work (for the most part I gotta fix my error checking to make sure if the meaning is empty it tells them no meaning found). Not sure how to get the information in the format it is in. Below will be an example. Basically need to get the year and the rank numbers in order to display.
Example of the data
<baby name=”Morgan”>
<rank year=”1900″>430</rank>
<rank year=”1910″>477</rank>
…
<rank year=”2000″>25</rank>
</baby>
My code
[CODE]
$(document).ready(function() {
//$(‘<p> Select a name from the list.</p>’).appendTo($(‘#allnames’));
$(‘#search’).hide();
$.ajax(
‘http://…./babynames.php’,
{
‘type’: “GET”,
‘data’: {“type”:”list”},
‘success’: showNames,
‘error’: ajax_failed
});
// hide loading image
$(‘#loadingmeaning’).hide();
$(‘#loadinggraph’).hide();
});
function showNames(data) {
$(‘#allnames’).removeAttr(‘disabled’);
$(‘#loadingnames’).hide();
var names = data.split(“n”);
var listLEN = names.length;
listLEN –;
//add the names into the list
for(var i = 0; i < listLEN; i++){
//console.log(names[i]);
$(‘<option>’).text(names[i]).click(getRankings).attr(‘value’, names[i]).appendTo($(‘#allnames’));
}
//$(‘#search’).click(showMeaning);
}
function showMeaning(){
$(‘#loadingmeaning’).show();
$(‘#resultsarea’).show();
$.ajax(
‘http://…./babynames.php’,
{
‘type’ : “GET”,
‘data’: {
‘type’: ‘meaning’,
‘name’: $(this).text(),
delay: 2
},
‘success’ : disMeaning,
‘error’ : ajax_failed,
});
$(‘#meaning’).empty();
}
function disMeaning(data){
var meaning = data;
//console.log(meaning);
$(‘#loadingmeaning’).hide();
if (!data){
$(‘<p> No meaning found! </p>’).appendTo($(‘#meaning’));
}
else{
$(‘<p>’ + meaning + ‘</p>’).appendTo($(‘#meaning’));
}
}
function getRankings(){
$(‘#resultsarea’).show();
$.ajax(
‘http://…./babynames.php’,
{
‘type’ : “GET”,
‘data’: {
‘type’: ‘rank’,
‘name’: $(this).text(),
delay: 2
},
‘success’ : disRanking,
‘error’ : ajax_failed
});
}
function disRanking(data){
$(‘#loadinggraph’).hide();
var rank = data;
console.log(rank);
}
// ajax_failed is a handler function for the ajax “error” event
function ajax_failed(xhr, status, error){
if (xhr.status == 404){
// error 404 has occurred
}
}