Trying to deal XML with Ajax

Tn

New Member
I Wrote a code that takes a generates XML file from Harvard Uni, and put it in a dropdown, next you can choose a course from the list and it will generates a table with the course details.\[code\] <script type="text/javascript" src="http://stackoverflow.com/questions/11544620/Script/jquery-1.7.2.js"></script> <script type="text/javascript"> $('#button').click(function () { document.getElementById("span").style.visibility = "visible"; document.getElementById("button").style.visibility = "hidden"; $.ajax({ type: "GET", url: "Harvard.aspx?field=COMPSCI", success: function (data) { var courses = data.documentElement.getElementsByTagName("Course"); var options = document.createElement("select"); $(options).change(function () { ShowCourseDetails(this); }); for (var i = 0; i < courses.length; i++) { var option = document.createElement("option"); option.value = http://stackoverflow.com/questions/11544620/$(courses).find("cat_num").text(); option.text = $(courses).find("title").text(); options.add(option, null); } document.getElementById("selectDiv").appendChild(options); document.getElementById("span").style.visibility = "hidden"; } }); }); function ShowCourseDetails(event) { // get the index of the selected option var idx = event.selectedIndex; // get the value of the selected option var cat_num = event.options[idx].value; $.ajax({ type: "GET", url: "http://courses.cs50.net/api/1.0/courses?output=xml&&cat_num=" + cat_num, success: function (data) { $("#TableDiv").html(ConvertToTable(data.documentElement)); } }); } function ConvertToTable(targetNode) { targetNode = targetNode.childNodes[0]; // first we need to create headers var columnCount = 2; var rowCount = targetNode.childNodes.length // name for the table var myTable = document.createElement("table"); for (var i = 0; i < rowCount; i++) { var newRow = myTable.insertRow(); var firstCell = newRow.insertCell(); firstCell.innerHTML = targetNode.childNodes.nodeName; var secondCell = newRow.insertCell(); secondCell.innerHTML = targetNode.childNodes.text; } // i prefer to send it as string instead of a table object return myTable.outerHTML; }</script>\[/code\]and the body:\[code\]<div id="main"> <div class="left"> <input id="button" type="button" value="http://stackoverflow.com/questions/11544620/Get all science courses from HARVARD"/> <br /> <span id="span" style="visibility: hidden">Downloading courses from harvard....</span> <div id="selectDiv"></div> <div id="TableDiv"></div> </div> </div>\[/code\]and What I get in the dropdown is only "undefined" on all the rows in the dropdown, can someone can see the problem with the code I wrote?10x alot in advance :)
 
Back
Top