Web Develop Forum: jQuery XML problem - Web Develop Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

jQuery XML problem Rate Topic: -----

#1 User is offline   Sam Granger Icon

  • Administrator
  • PipPipPip
  • Group: Root Admin
  • Posts: 431
  • Joined: 22-October 08
  • Gender:Male

Posted 27 December 2009 - 06:35 PM

I'm not sure what I am doing wrong, but I cannot seem to extract information from an XML using jQuery. The XML does get loaded, so that isn't the problem.

What the XML looks like:
<?xml version="1.0" encoding="utf-8"?>
<ping>
    <pong>Hello world</pong>
</ping>


What my jQuery looks like:
$(document).ready(function(){
    var userStatus;
    $.ajax({
        type: "GET",
        url: "/ping/user_status/",
        dataType: "xml",
        success: function(xml) {
            userStatus = $(this).find('pong').text();
            $('#userstatus').html(userStatus);
        }
    });
});


Any clues where I might be going wrong? :mellow:
0

#2 User is offline   Salathe Icon

  • Advanced Member
  • Icon
  • Group: Moderator
  • Posts: 138
  • Joined: 15-January 09
  • Gender:Male
  • Location:Scotland

Posted 27 December 2009 - 06:49 PM

Looks like you'll be wanting to use
var userStatus = $(xml).find('pong').text();

salathe@php.net
0

#3 User is offline   Sam Granger Icon

  • Administrator
  • PipPipPip
  • Group: Root Admin
  • Posts: 431
  • Joined: 22-October 08
  • Gender:Male

Posted 27 December 2009 - 07:07 PM

Thanks Salathe, but already tried that already without any luck :(.

Live demo: http://explore2.com/
0

#4 User is offline   Salathe Icon

  • Advanced Member
  • Icon
  • Group: Moderator
  • Posts: 138
  • Joined: 15-January 09
  • Gender:Male
  • Location:Scotland

Posted 27 December 2009 - 08:29 PM

Send the XML response back with an XML content type header:

header('Content-Type: text/xml;charset=utf-8');

salathe@php.net
0

#5 User is offline   Sam Granger Icon

  • Administrator
  • PipPipPip
  • Group: Root Admin
  • Posts: 431
  • Joined: 22-October 08
  • Gender:Male

Posted 27 December 2009 - 10:09 PM

Thanks Peter, so simple yet effective! Didn't know that would make much difference due to file structure but it did the trick! ;)
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users