Xml http request ajax

hi I’m developing an application with phonegap framework [beginner]
[Html 5 / css3 / jquery mobile / jquery / javascript] how I can display the content of the xml file in my application
using the technique to xml http request from ajax to display the contents of the xml file in the mobile query

I’m not sure I understand the question correctly.
Are you trying to fetch an XML file via Ajax and parse the result?

yes that’s it

for example
i have this data on xml file

<cars>
 <car> <name>X</name><id>1</id></car>
 <car> <name>Y</name><id>2</id></car>
<car> <name>salim</name><id>3</id></car>
</cars>

i want to display this on listview using ajax & xmlhttprequest
thanks

Well, a simple example would be:

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Fetch and parse XML demo</title>
  </head>
  <body>
    <ul></ul>

    <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script>
      $.ajax({
        type: "GET",
        url: "cars.xml",
        dataType: "xml",
        success: function(xml){
          $(xml).find('car').each(function(){
            var id = $(this).find('id').text();
            var name = $(this).find('name').text();
            $("<li></li>").html(id + ": " + name).appendTo("ul");
          });
        },
        error: function(){
          console.log("An error occurred while processing XML file.");
        }
      });
    </script>
  </body>
</html>

cars.xml

<cars>
  <car>
    <id>1</id>
    <name>Audi</name>
  </car>
  <car>
    <id>2</id>
    <name>Porsche</name>
  </car>
  <car>
    <id>3</id>
    <name>Mercedes</name>
  </car>
</cars>

This would produce:

  • 1: Audi
  • 2: Porsche
  • 3: Mercedes

hi thanks mate but how can i add the xmlhttprequest

The jQuery $.ajax() method replaces the browser native XMLHttpRequest object.
The result is the same, though.

You can read more here: http://www.sitepoint.com/jqxhr-object/

okey it works i tried and it’s cool
but now
i want to do the same thing with authentication login[admin] & password [ admin ]
i receive them from a xml file to login
and if there i put something else in the box i can’t login

and i searched for while but no results

Sorry, I don’t understand.
You receive the login credentials from an XML file?

i tested what you posted don’t work :(( for parsing xml data

Lol. Make up your mind.
Also, a bit more information would be nice if you need help with anything specific.

1 Like

sorry man i tested usuing other example but it did not work

You have to be more explicit about what you are trying to do, what code you have, what you expected to happen, what actually happened and so on.
Maybe read this: http://sscce.org/

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.