mikemastah Posted May 15, 2009 Share Posted May 15, 2009 I was wondering how would I do something like this with ajax. I have a variable (user input) 'uuc' and i want the value 'phe' returned this is my xml file: <aminoacids> <mrnacodes> <ID>2</ID> <mrna>uuc</mrna> <aminocode>phe</aminocode> </mrnacodes> <mrnacodes> <ID>1</ID> <mrna>uuu</mrna> <aminocode>phe</aminocode> </mrnacodes> <mrnacodes> <ID>3</ID> <mrna>uua</mrna> <aminocode>leu</aminocode> </mrnacodes> etc..... </aminoacids> Quote Link to comment Share on other sites More sharing options...
Floydian Posted May 15, 2009 Share Posted May 15, 2009 Re: Actually use xml with ajax Most people I know use a javascript/ajax library that will take the xml and parse it for you, turning it into a javascript object. You would then be able to access all those fields just like any other javascript object. Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted May 16, 2009 Share Posted May 16, 2009 Re: Actually use xml with ajax I would personally use JSon instead of XML for the good reason it takes less space, and is easier / faster to decode by Javascript: http://www.json.org/js.html The quickest way: mydata=('(' + myJSONtext + ')'); If you want to keep XML: http://www.captain.at/howto-ajax-process-xml.php Quote Link to comment Share on other sites More sharing options...
mikemastah Posted May 16, 2009 Author Share Posted May 16, 2009 Re: Actually use xml with ajax JSON looks pretty hard :) so how would I do the parser thing? the problem is that I do not have access to PHP, MySQL, etc. only javascript. I could rewrite the xml file to <aminoacids> <uuc> <aminocode>phe</aminocode> </uuc> <uuu> <aminocode>phe</aminocode> </uuu> <uua> <aminocode>leu</aminocode> </uua> etc... </aminoacids> would that be easier? Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted May 16, 2009 Share Posted May 16, 2009 Re: Actually use xml with ajax The JSon parser is just matter of doing an eval in Javascript. To write JSON from PHP: echo "myJSObject={name:'value',name2:'value',name3:1,jsArray:['a','b','c']}"; Quote Link to comment Share on other sites More sharing options...
mikemastah Posted May 16, 2009 Author Share Posted May 16, 2009 Re: Actually use xml with ajax But how would I use JSON for what I need? To be completely honest I have no clue what an eval is... Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted May 16, 2009 Share Posted May 16, 2009 Re: Actually use xml with ajax eval in Javascript let you run a javascript script as it was a javascript code. So basically you feed your JSon to the eval and you get the object back. I would suggest you to check some tutorials websites how to do those things. Quote Link to comment Share on other sites More sharing options...
mikemastah Posted May 16, 2009 Author Share Posted May 16, 2009 Re: Actually use xml with ajax ok thanks for the help, Issue is solved. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.