I have found jQuery to be one of the most powerful JavaScript libraries out there at the minute. I’ve been working with the base library and a number of plug-ins over the past couple of weeks and have found both the effects and AJAX methods to be both powerful and easy.
Here’s some code that I have used to look up an address. The data is served by an .aspx (.NET) page and I have included an example of the returned XML below.
jQuery code:
//Perform Ajax call – notice the number and postcode – these end up as querystring params and are taken in by AddressFinder.aspx
//’xml’ is an XML document object holding the returned XML
jQ.ajax({ type: “POST”, url: “AddressFinder.aspx”, data: “number=1&postcode=wn58ln”, dataType: “xml”, success: function(xml){//This simple XPath XML function looks through the returned XML data
//All tags can now be accessed within the loop
var _number = “”;
var _line1 = “”;
var _town = “”;
var _city = “”;
var _country = “”;//This function will loop for each match on addresses/address
jQ(“/addresses/address”, xml).each(function(){_number = jQ(“number”, this).text();
_line1 = jQ(“line1″, this).text();
_town = jQ(“town”, this).text();
_city = jQ(“city”, this).text();
_country = jQ(“country”, this).text();jQ(“#text11″).val(_line1);
jQ(“#text12″).val(_town);
jQ(“#text13″).val(_city);
jQ(“#text14″).val(_country);
});
XML returned from AddressFinder.aspx:
<?xml version=”1.0″ encoding=”utf-8″ ?>
<addresses>
<address>
<number>6</number>
<line1>Almsberry Cresent</line1>
<town>Ashton – in – Makerfield</town>
<city>Wigan</city>
<country>England</country>
</address>
</addresses>
Did you find this demonstration helpful? If so leave me a comment and let me know if there are any other AJAX exmaples you’d like to see here. Thanks.
28 January, 2007 at 11:50 am |
I know that it might seem obvious, but it is very important to remember to set the text/xml content type on the http headers.
One thing that I do miss is the ability to select properties in a xml document like tada. How would you go about selecting the number in this case?
29 January, 2007 at 10:52 pm |
Lars,
I’m not totall sure what you mean here. why not send me an email on chris_gaskell at blueyonder dot co dot uk.
Thanks,
Chris
2 February, 2007 at 11:02 am |
Hi,
I want to parse the soap respone . How I can do this using Xpath ?
Muki
21 May, 2007 at 3:07 am |
Hi,
How can i get the node names in jquery?.because nodeName is not working here.is there any Jquery statement so that i can print all node Names.
Thanks
Kanchana
27 July, 2007 at 2:41 am |
This was very helpful.
Thanks alot Chris!
27 August, 2007 at 12:39 am |
Lars, thank you for stating the obvious about sending the good content-type back.
You just ended my 3 hours of insane debugging, test-casing, head-banging… you name it
All that because i forgot to specify “text/xml” im my PHP file :S
So long story short for everyone else google’ing around: if IE fails at XML parsing but Firefox is okay, be sure to add this line in your php file:
header(‘Content-type: text/xml’);
Javascript will then treat this input as a valid XML (and IE wont crash on it!)
Many thanks
3 September, 2007 at 11:33 am |
Chris,
this kinda example on XML parsing is not even mentioned in JQuery site tutorials. It is really helpful for me.
Thank you very much
13 September, 2007 at 1:32 am |
Thank you for the clear example. I need to try it out ASAP for a current project.
Please write more of these posts!
14 September, 2007 at 7:09 pm |
Nice example ! Thanks
22 October, 2007 at 7:52 pm |
Thanks Bilange, you saved me a lots of time
21 November, 2007 at 3:12 pm |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
5 December, 2007 at 12:42 pm |
[...] Plugin jQuery Ajax call and result XML parsing xmlObjectifier – Converts XML DOM to JSON jQuery XSL Transform jQuery Taconite – multiple Dom [...]
5 December, 2007 at 7:45 pm |
I’m having a straight xml load fail on one of my companies servers, but not another server and only in IE, unfortunitly, the server it fails on is the one I need for production. IE works on the other non-production server. Any ideas? Can you do just a straight xml file load like this?
$.ajax({
type: “Get”,
url: “ambassadors.xml”,
dataType: “xml”,
6 December, 2007 at 1:22 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
16 December, 2007 at 12:21 pm |
Thank you very much for your comments everyone. It helped me a lot to debug one of my web applications.
1 January, 2008 at 11:37 am |
[...] jQuery Ajax call and result XML parsing. [...]
24 January, 2008 at 8:16 am |
Code markup is awful. Can You fix it, please? Completely unreadable.
19 February, 2008 at 8:03 pm |
A Realistic $250K First Year Income Potential
Less than four years ago I was driving this beat-up ‘94 VW with a rusty muffler. Within two years of creating this system I was making more than my doctor, accountant, and attorney COMBINED… while working less than 40 hours a week FROM HOME! Together with my group of leaders we are now seeking qualified entrepeneurs sharein the incredible results of our system.
for more information check this site out….
Reverse Funnel System
4 March, 2008 at 11:18 am |
I changed it slightly
response = $(‘feedback’, this).text();
Thank you very much! Really helpful
4 March, 2008 at 1:30 pm |
good help
12 March, 2008 at 12:34 am |
Great! this is an example that I need and couldn’t find in official jQuery’s site.
Thank you
3 April, 2008 at 4:41 am |
[...] Plugin jQuery Ajax call and result XML parsing xmlObjectifier – Converts XML DOM to JSON jQuery XSL Transform jQuery Taconite – multiple Dom [...]
9 April, 2008 at 10:05 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
15 May, 2008 at 9:47 pm |
Hi All,
I’m an author of jQuery plugin(s) that specifically handle cases of working with SOAP web services and other XML responses. So if you’re really in need of a solution please visit my site http://www.terracoder.com. Link to it is also available from jQuery site. Enjoy!!!
25 June, 2009 at 2:03 pm |
Sam,
I’m really interested in jsXMLUtils JQuery plugin, but your site http://www.terracoder.com it’s not working since several days due to site maintenance,..
Do I have to go to any other url to reach docs, samples, etc ?
Thanks in advance !!!
16 May, 2008 at 11:36 am |
[...] jQuery Ajax call and result XML parsing [...]
17 May, 2008 at 6:25 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
28 May, 2008 at 8:59 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
31 May, 2008 at 3:54 pm |
thank you. its a very usefull example.
30 June, 2008 at 9:50 am |
[...] jQuery Ajax call and result XML parsing. [...]
1 July, 2008 at 5:31 pm |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
7 August, 2008 at 9:40 am |
Please note that XPath support was removed in jQuery 1.2, so the above example does not work anymore in its current form.
replace
/addresses/address
with the css selector
>addresses>address
2 September, 2008 at 2:53 pm |
more information here…
Nice Content Very Usseful…
23 September, 2008 at 3:18 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
29 September, 2008 at 6:34 pm |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
9 October, 2008 at 6:53 pm |
nice tutorial!! thanks!!
11 October, 2008 at 6:03 pm |
[...] jQuery xml parsing [...]
12 October, 2008 at 9:22 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
31 October, 2008 at 1:47 pm |
[...] jQuery Ajax call and result XML parsing [...]
19 November, 2008 at 11:02 am |
nice works, it a great help …
2 December, 2008 at 2:20 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
2 December, 2008 at 3:15 am |
[...] jQuery Ajax call and result XML parsing. [...]
7 December, 2008 at 4:35 pm |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
18 December, 2008 at 10:42 am |
[...] jQuery Ajax call and result XML parsing. [...]
24 December, 2008 at 1:07 am |
Очень признателен, действительно полезная инфа.
5 January, 2009 at 6:23 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
8 January, 2009 at 12:31 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
4 February, 2009 at 9:13 am |
[...] Plugin jQuery Ajax call and result XML parsing xmlObjectifier – Converts XML DOM to JSON jQuery XSL Transform jQuery Taconite – multiple Dom [...]
6 February, 2009 at 6:14 am |
[...] Plugin jQuery Ajax call and result XML parsing xmlObjectifier – Converts XML DOM to JSON jQuery XSL Transform jQuery Taconite – multiple Dom [...]
7 February, 2009 at 3:20 pm |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
12 February, 2009 at 5:47 pm |
[...] jQuery Ajax call and result XML parsing. [...]
21 February, 2009 at 2:42 am |
[...] jQuery Ajax call and result XML parsing [...]
25 February, 2009 at 3:53 am |
[...] jQuery Ajax call and result XML parsing. [...]
28 February, 2009 at 12:41 am |
[...] jQuery Ajax call and result XML parsing [...]
3 March, 2009 at 3:39 pm |
[...] Plugin jQuery Ajax call and result XML parsing xmlObjectifier – Converts XML DOM to JSON jQuery XSL Transform jQuery Taconite – multiple Dom [...]
5 March, 2009 at 1:34 am |
[...] jQuery Ajax call and result XML parsing [...]
29 March, 2009 at 12:26 pm |
Автор, а скажите а куда написать по поводу обмена ссылок (на какое конкретно мыло)?
31 March, 2009 at 4:18 pm |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
7 April, 2009 at 7:55 pm |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
9 April, 2009 at 2:39 am |
[...] Plugin . jQuery Ajax call and result XML parsing . xmlObjectifier – Converts XML DOM to JSON . jQuery XSL Transform . jQuery Taconite – multiple Dom [...]
11 April, 2009 at 11:48 pm |
Эх… После прочтения даже мне эта тема стала интересна.
29 April, 2009 at 7:20 pm |
te
1 May, 2009 at 2:43 pm |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
8 May, 2009 at 2:48 am |
Hello…
Gotta love google, very neat stuff. Thanks….
4 June, 2009 at 7:19 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
7 June, 2009 at 10:54 pm |
This is most helpful. Could you put up what the .net program looks like. I have interfaced with a php pgm but do not understand the mechanics of a .net.
10 June, 2009 at 8:49 am |
[...] jQuery Ajax call and result XML parsing. [...]
19 June, 2009 at 10:33 am |
Very helpful. I just retrieved the xml data from my webservice using jquery ajax. Now I will be manipulating the xml received.
Thank you.
22 June, 2009 at 12:43 pm |
[...] Plugin jQuery Ajax call and result XML parsing xmlObjectifier – Converts XML DOM to JSON jQuery XSL Transform jQuery Taconite – multiple Dom [...]
3 July, 2009 at 4:34 pm |
Thanks for your post! I’m sure all of us appreciate the fact that you’ve taken the time to take your findings, big or small, and share them with the rest of our web developing community!
11 July, 2009 at 9:32 am |
Thank you very much Lars and Bilange about your comments about including the right xml header. I wish I had read this before I wasted 2-3 hours trying to debug my own application.
20 July, 2009 at 10:19 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – [...]
21 July, 2009 at 1:19 am |
[...] jQuery Ajax call and result XML parsing. [...]
4 August, 2009 at 12:29 am |
[...] Plugin jQuery Ajax call and result XML parsing xmlObjectifier – Converts XML DOM to JSON jQuery XSL Transform jQuery Taconite – multiple Dom [...]
5 August, 2009 at 3:53 pm |
[...] [...]
7 August, 2009 at 9:06 am |
[...] jQuery Ajax call and result XML parsing. [...]
7 August, 2009 at 12:38 pm |
[...] jQuery Ajax call and result XML parsing. [...]
9 August, 2009 at 2:27 pm |
[...] Plugin.jQuery Ajax call and result XML parsing.xmlObjectifier – Converts XML DOM to JSON.jQuery XSL Transform.jQuery Taconite – multiple Dom [...]
12 August, 2009 at 7:31 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – [...]
13 August, 2009 at 10:59 am |
[...] jQuery Ajax call and result XML parsing. [...]
18 August, 2009 at 1:03 pm |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
29 August, 2009 at 3:30 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple Dom [...]
2 September, 2009 at 3:15 pm |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – [...]
9 September, 2009 at 7:50 am |
[...] jQuery Portlets. jqDnR – drag, drop resize. Drag Demos. XML XSL JSON FeedsXSLT Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – [...]
14 September, 2009 at 2:02 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – [...]
29 September, 2009 at 3:31 pm |
[...] Plugin jQuery Ajax call and result XML parsing xmlObjectifier – Converts XML DOM to JSON jQuery XSL Transform jQuery Taconite – multiple Dom [...]
9 October, 2009 at 8:53 pm |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – multiple [...]
13 October, 2009 at 8:32 am |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – [...]
18 November, 2009 at 3:03 pm |
[...] Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – [...]
8 December, 2009 at 9:29 am |
[...] XSL JSON Feeds XSLT Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – [...]
9 December, 2009 at 2:52 am |
[...] jQuery Ajax call and result XML parsing. [...]
9 December, 2009 at 9:13 am |
[...] XSL JSON Feeds XSLT Plugin. jQuery Ajax call and result XML parsing. xmlObjectifier – Converts XML DOM to JSON. jQuery XSL Transform. jQuery Taconite – [...]