0

My XML file:

<?xml version="1.0"?>
 <xml>
  <weather>
   <location>Wonderland</location>
   <temp>20</temp>
  </weather>
 </xml>

My javascript:

<script type="text/javascript">
// <![CDATA[
$(document).ready(function(){

 $.ajax({

  type: "GET",

  url: "https://..../Weather.php",

  dataType: "xml",

   success: function(xml) {

    $(xml).find('weather').each(function(){

     var location = $(this).find("location").text();

     var temp = $(this).find("temp").text();

     $("#footer").append(temp+location);

      });

     }

     });

   });

  // ]]>

 </script>


Can somebody please show me where I was wrong? Thank you very much

Xitrum
  • 7,765
  • 26
  • 90
  • 126
  • Did you run your code? error? – Khurshid Oct 02 '12 at 11:14
  • i ran it but i didn't see value from xml file, i tried printing something after success: function(xml) but i didn't show up – Xitrum Oct 02 '12 at 11:21
  • you should check your ajax url manually with your browser or with console.log(xml) – Khurshid Oct 02 '12 at 11:26
  • actually, the url on a ftp server and I just ran my web page locally, will that cause problems? – Xitrum Oct 02 '12 at 11:29
  • Yes, you could run into cross-origin errors. See http://stackoverflow.com/questions/12683530/origin-http-localhost-is-not-allowed-by-access-control-allow-origin/12683591#comment17119419_12683591 – Nate Higgins Oct 02 '12 at 11:39

1 Answers1

1

You could take a look at Origin http://localhost is not allowed by Access-Control-Allow-Origin.? - You may be running into cross-origin issues.

Community
  • 1
  • 1
Nate Higgins
  • 2,104
  • 16
  • 21