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");
        }
    });
}

2 Answers 2

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);
  }
});
Sign up to request clarification or add additional context in comments.

3 Comments

i have an error ! firebug show me "XML can't be the whole program"
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: <item> <category> <title>sport</title> <url>xml/sport.xml</url> </category> <category> <title>cinema</title> <url>xml/cinema.xml</url> </category> <category> <title>language</title> <url>xml/language.xml</url> </category> <category> <title>country</title> <url>xml/country.xml</url> </category> </item>
It seems it expecting an script json object instead of xml. Try YQL or github.com/jamespadolsey/jQuery-Plugins to load cross domain xml.
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.

2 Comments

so how can i load xml data from this url? do you have any suggestion for me ?
Sure... You only have to read my Answer (Possible Solution) :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.