1

I want to read a xml file generated from Drupal 7 using JQuery and Ajax.

When I type the http url link in url:' ' the Ajax function doesn't retrieve any data.

When I type my xml file as a local file (without http url) the Ajax function works normally.

The Ajax code is:

$(document).ready(function () {
    $.ajax({
        type: "GET",
        url: "any http url that contains xml file",
        dataType: "xml",
        success: xmlParser
    });
});

function xmlParser(xml) {

$('#load').fadeOut();

$(xml).find("movie-info").each(function () {

    $(".main").append('<div class="book"><div class="title">' + $(this).find("title").text() + '</div><div class="description">' + $(this).find("field_genre").text() + '</div><div class="date">Published ' + $(this).find("field_poster").text() + '</div></div>');
    $(".book").fadeIn(1000);

});  
Paulo Tomé
  • 1,910
  • 3
  • 18
  • 27
  • possible duplicate of [Ways to circumvent the same-origin policy](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – Quentin Aug 18 '13 at 20:45
  • A good reading on the JQuery AJAX cross domain subject:http://stackoverflow.com/a/11736771/2152558 – Paulo Tomé Aug 18 '13 at 23:30

1 Answers1

1

For cross domain jQuery ajax calls you have only 2 reliable options:

1: use a proxy script that makes the request for you on the same domain as the page that needs to request the xml

http://wiki.asp.net/page.aspx/1430/aspnet-proxy-page--used-for-cross-domain-requests-from-ajax-and-javascript/

2: make the cross-domain server support CORS.

http://www.html5rocks.com/en/tutorials/cors/

Also there is another option(JSON-P) that is not recommended due to security concerns and also it doesn't work for your case.

http://www.ibm.com/developerworks/library/wa-aj-jsonp1/

Code.Town
  • 1,216
  • 10
  • 16