0

Having an issue with an AJAX call. I think this big, funky function that in essence gives back a yes/now for a string.

usdaurl = 'http://eligibility.sc.egov.usda.gov/eligibility/eligibilityservice?eligibilityType=Property&requestString=<?xml version="1.0"?><Eligibility xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="/var/lib/tomcat5/webapps/eligibility/Eligibilitywsdl.xsd"><PropertyRequest StreetAddress1="'+street+'" StreetAddress2="" StreetAddress3="" City="'+city+'" State="'+state+'" County="" Zip="'+zip+'" Program="RBS"></PropertyRequest></Eligibility>';
$.ajax({
    url: usdaurl,
    dataType: 'XML',
    success: function(xml){
        var usda = $('Property').attr('Eligibility');
    }
});

This is the simple version, I've drilled the problem down to this function. This is the error I keep getting:

XMLHttpRequest cannot load http://eligibility.sc.egov.usda.gov/eligibility/eligibilityservice?eligibil…%2262034%22%20Program=%22RBS%22%3E%3C/PropertyRequest%3E%3C/Eligibility%3E. 
Origin http://[mydomain ;)] is not allowed by Access-Control-Allow-Origin. 

The URL that the query is trying to access works. If I just put it in to a browser, I get back some XML. But when I try to use AJAX, I get this error.

Plummer
  • 6,522
  • 13
  • 47
  • 75
  • Doing this via ajax is bad. Consider doing a 1px iframe. Opening the cross site scripting door can be a slippery slope of doom. – Joe Mills Mar 05 '13 at 05:51
  • So the source url of the 1px iframe is the URL of the AJAX call? How do you drill down into that iframe? Any reference links you could share? – Plummer Mar 05 '13 at 05:55
  • *GASP!* http://stackoverflow.com/questions/8676478/how-to-access-element-present-inside-a-iframe-from-parent-window Might this be what you're talking about? – Plummer Mar 05 '13 at 05:59

1 Answers1

2

Ajax is not allowed to call other domains out of the box. There are some browser specific workarounds.

Daniel Williams
  • 8,673
  • 4
  • 36
  • 47