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

});  
2

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

Comments

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.