0

if you copy http://tgbs.ir/xml/Category.xml in your browser , you will see content of xml file. but in below code alert doesnt show and i think url doesnt work . please help me to solve this problem because this code has to read from this url.

Date.ReadCategoryXml = function() {
    var counter=0;
    $.ajax({
        type: "GET",
        url: "http://tgbs.ir/xml/Category.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find("category").each(function() {
                var cTitle = $(this).find("title").text()
                var cUrl = $(this).find("url").text();
                Data.arrCategory[counter++]= new Category(cTitle,cUrl);
            });
            alert("behnaz");
        }
    });
}
mu is too short
  • 426,620
  • 70
  • 833
  • 800

2 Answers2

2

You can try using jsonp to get cross domain calls More info @ http://api.jquery.com/jQuery.ajax/

Example

$.ajax({
  url: 'http://tgbs.ir/xml/Category.xml',
  dataType: 'jsonp',
  success: function( data ) {
      alert("Success : "+data);
  }
});
Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • i have an error ! firebug show me "XML can't be the whole program" – B.T Tasharofi Sep 26 '11 at 08:21
  • i have an error ! firebug show me "XML can't be the whole program" . and when alert error , show message " parse error ".this xml file include tags: sport xml/sport.xml cinema xml/cinema.xml language xml/language.xml country xml/country.xml – B.T Tasharofi Sep 26 '11 at 08:31
  • It seems it expecting an script json object instead of xml. Try YQL or https://github.com/jamespadolsey/jQuery-Plugins to load cross domain xml. – Jayendra Sep 26 '11 at 09:04
1

http://tgbs.ir the Domain where the script runs? If not… You can't load xml data from an other Domain because of the Same origin policy

Possible Solution: craigslist rss feed

In short... you have to build a wrapper function which gets your data.

Community
  • 1
  • 1
gearsdigital
  • 13,915
  • 6
  • 44
  • 73