February 26, 201313 yr Unfortunately JS and jQuery, past the necessities has never been much of my strong point and I've hit a bit of a snag attempting to output the XML produced from the typical "REST service I made earlier", having tried a number of solutions I'm at my wits end... A sample data set and example JS is below, though this would typically be returned based on the provided url, it seems any attempt to use a url or external XML file fail. $(document).ready(function() { $.get('http://localdev/books/course/CC150/xml', function(d){ $('body').append('<h1> Recommended Web Development Books </h1>'); $('body').append('<dl>'); $(d).find('book').each(function(){ var $book = $(this); var id = $book.attr("id"); var title = $book.attr("title"); var isbn = $book.attr("isbn"); var borrowedcount = $book.attr("borrowedcount"); var html = '<dd><p> ' + id + '</p>' ; html += '<p> ' + title + '</p>' ; html += '<p> ' + isbn + '</p>' ; html += '<p> ' + borrowedcount + '</p>' ; html += '</dd>'; $('dl').append($(html)); $('.loadingPic').fadeOut(1400); }); }); }); <?xml version="1.0" encoding="UTF-8"?> <results> <course>CC150</course> <books> <book id="370955" title="Schaum's outline of UML" isbn="77096738" borrowedcount="212"/> <book id="422148" title="Human-computer interaction" isbn="130461091" borrowedcount="210"/> <book id="228015" title="Computer networks" isbn="133942481" borrowedcount="197"/> .......... </books> </results> Edited February 26, 201313 yr by CSN-UK
February 26, 201313 yr Author Bit of an update for the benefit of those whom may in future experience a similar issue, It was DNS related, the localhost (LAMP/WAMP) server could not be found by $.get as it appeared to be querying the network DNS rather than considering the local DNS /localhost, thus returning a 404 file not found, works perfectly in a live environment however with the appropriate public URLs. Edited February 26, 201313 yr by CSN-UK
Create an account or sign in to comment