The code above doesn't work because it has bugs-- there is nothing MySpace specific to the failure. That's OK. To me, that just means I don't need to file any bug reports against the container team:)
So, what are the errors? First, the init() method should be added to the startup via gadgets.util.registerOnLoadHandler(fn). This makes sure that the function only gets called once all the OpenSocial infrastructure is loaded. Otherwise, your code will fall prey to some race conditions where other scripts aren't available due to slower loading browsers. Second, consider using gadgets.io.makeRequest instead of the MySpace specific opensocial.Container.get() pattern. This allows your code to be more portable to other containers with less work. Third, arguments[0] is undefined when the callback is executed. The alert never happens because MySpace disables alert. The value you want to use is arguments.data. Last, .nodeValue is null. I'm assuming you wanted to display "Vada Spa", which would happen via textContent in FF and text in IE. I've taken the liberty of updating your code and testing it on MySpace from both IE and FF. <div id='main'> <div id='loading'><img src='http://www.viphaklay.com/jquery/ spinner.gif'/></div> </div> <script type="text/javascript"> function init() { var params = {}; params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT; var url="http://www.lifebooker.com/search/results.xml? limit=1&direction=desc" + "&page=1&service_categories%5B%5D=8&inclusive_search=0&gender=3" + "&minimum_discount=0&maximum_discount=-1&zones%5B%5D=25&zones%5B %5D=26" + "&zones%5B%5D=29&zones%5B%5D=1&zones%5B%5D=2&zones%5B%5D=3&zones%5B %5D=4" + "&zones%5B%5D=5&zones%5B%5D=6&zones%5B%5D=7&zones%5B%5D=8&zones%5B %5D=9" + "&zones%5B%5D=30&zones%5B%5D=11&zones%5B%5D=13&zones%5B%5D=15&zones%5B %5D=17" + "&zones%5B%5D=31&zones%5B%5D=10&zones%5B%5D=12&zones%5B%5D=14&zones%5B %5D=16&" + "zones%5B%5D=18&zones%5B%5D=27&zones%5B%5D=19&zones%5B%5D=20&zones%5B %5D=21" + "&minimum_price=0&maximum_price=-1&minimum_time=600&maximum_time=2400&quantity=1"; gadgets.io.makeRequest(url,callback_fn,params); } function callback_fn(arguments){ var useStandard = true; var main = document.getElementById("main"); if (window.ActiveXObject) { //Internet Explorer xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; useStandard = false; xmlDoc.loadXML(arguments.data); } else { parser=new DOMParser(); xmlDoc=parser.parseFromString(arguments.data,"text/xml"); } var node = xmlDoc.getElementsByTagName('name')[0]; if (useStandard){ main.innerHTML=node.textContent; } else { main.innerHTML = node.text; } } gadgets.util.registerOnLoadHandler(init); </script> On Feb 13, 12:24 pm, Anthony Long <[email protected]> wrote: > <div id='main'> > <div id='loading'><img src='http://www.viphaklay.com/jquery/ > spinner.gif'/></div> > </div> > <script type="text/javascript"> > function init() { > var params = {}; > params[gadgets.io.RequestParameters.CONTENT_TYPE] = > gadgets.io.ContentType.TEXT; > > var url="http://www.lifebooker.com/search/results.xml? > limit=1&direction=desc&page=1&service_categories%5B > %5D=8&inclusive_search=0&gender=3&minimum_discount=0&maximum_discount=-1&zones > %5B%5D=25&zones%5B%5D=26&zones%5B%5D=29&zones%5B%5D=1&zones%5B > %5D=2&zones%5B%5D=3&zones%5B%5D=4&zones%5B%5D=5&zones%5B%5D=6&zones%5B > %5D=7&zones%5B%5D=8&zones%5B%5D=9&zones%5B%5D=30&zones%5B%5D=11&zones > %5B%5D=13&zones%5B%5D=15&zones%5B%5D=17&zones%5B%5D=31&zones%5B > %5D=10&zones%5B%5D=12&zones%5B%5D=14&zones%5B%5D=16&zones%5B > %5D=18&zones%5B%5D=27&zones%5B%5D=19&zones%5B%5D=20&zones%5B > %5D=21&minimum_price=0&maximum_price=-1&minimum_time=600&maximum_time=2400&quantity=1"; > opensocial.Container.get().makeRequest(url,callback_fn,params);} > > function callback_fn(arguments){ > var main = document.getElementById("main"); > try { //Internet Explorer > xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); > xmlDoc.async="false"; > xmlDoc.loadXML(arguments[0]); > } catch(e){ > try { //Firefox, Mozilla, Opera, etc. > parser=new DOMParser(); > xmlDoc=parser.parseFromString(arguments[0],"text/xml"); > } catch(e){ > alert(e.message); > return; > } > } > main.innerHTML=xmlDoc.getElementsByTagName('name')[0].nodeValue;} > > init(); > > </script> > > Not sure why this isnt parsing and displaying the string inside <name> > tag. Any help would be appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Implementing OpenSocial Containers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/opensocial-container?hl=en -~----------~----~----~----~------~----~------~--~---
