Ajax XML response is NULL

sainiy

New Member
What I am trying to do is to get the XML from the ajax request in order to extract data out of it (using the DOM, not that it matters). No I do know that the ajax works just fine because if i try and get the AjaxRequest.responseText, it works alright. The error message that i am Getting is saying that:'null' is not an object (evaluating 'resturantsCategoriesAjaxXML.getElementsByTagName')and when i try to write the responseXML to the log, all i get is null, like it hasn't been defined. I have included the full JS that handles the AJAX (sorry for the weird variable names, I just didn't want to change them in case the problem is a typo), and the XML that it is fetching (simple XML). Thanks a lot for your help :DJava Script:\[code\]resturantsCategoriesAjaxRequestAdress = "testFiles/categoriesAjax.xml";resturantsCategoriesAjaxRequest = new XMLHttpRequest();resturantsCategoriesAjaxRequest.onreadystatechange = function(){if(resturantsCategoriesAjaxRequest.readyState == 4){ resturantsCategoriesAjaxXML = resturantsCategoriesAjaxRequest.responseXML; console.log(resturantsCategoriesAjaxRequest.responseXML); categoriesArray = resturantsCategoriesAjaxXML.getElementsByTagName("category"); categoriesArraylenght = categoriesArray.length; alert(categoriesArraylenght); categoriesArrayIritationControl = 0; while (categoriesArraylenght >= categoriesArrayIritationControl) { categoryName = categoriesArray[categoriesArrayIritationControl].getAttribut("name"); //create new <li> object //add to ctegories menu on restrants page alert(categoryName); }}}resturantsCategoriesAjaxRequest.open("GET", resturantsCategoriesAjaxRequestAdress, true);resturantsCategoriesAjaxRequest.overrideMimeType("text/xml");resturantsCategoriesAjaxRequest.send();console.log(resturantsCategoriesAjaxRequest.readyState);\[/code\]XML:\[code\]<?xml version='1.0'?><category name="Fast_Food" id="1120"></category><category name="Chinese" id="1108"></category><category name="Italian" id="1230"></category>\[/code\]
 
Back
Top