0

I have a URI that takes an XML arg and returns an XML result. Works superbly when I run it in a browser by itself.

I need to use this script as part of an AJAX query, so I was hoping to get a result from the URL and then just echo it out to the AJAX call. I've tried using fopen, but I don't get a result.

Is there a simple way to accomplish this? I've seen references to using a proxy, but can't find an example of how to do that with php.

$street = $_GET['street'];
$city = $_GET['city'];
$state = $_GET['state'];
$zip = $_GET['zip'];

$url = 'http://eligibility.cert.sc.egov.usda.gov/eligibility/eligibilityservice?eligibilityType=Property&requestString=';
$url_query = '%3C?xml%20version=%221.0%22?%3E%3CEligibility%20xmlns:xsi=%22http://www.w3.org/2001/XMLSchema-instance%22%20xsi:noNamespaceSchemaLocation=%22/var/lib/tomcat5/webapps/eligibility/Eligibilitywsdl.xsd%22%3E%3CPropertyRequest%20StreetAddress1=%22'.$street.'%20street%22%20StreetAddress2=%22%22%20StreetAddress3=%22%22%20City=%22'.$city.'%22%20State=%22'.$state.'%22%20County=%22%22%20Zip=%22'.$zip.'%22%20Program=%22RBS%22%3E%3C/PropertyRequest%3E%3C/Eligibility%3E';
$url_final = $url.''.$url_query;

$return = fopen($url_final);
echo $return;
2
  • Can you add some more details such as what the output should look like? Commented Mar 18, 2013 at 19:08
  • Return is just XML. I'm hoping I can then echo that XML to the AJAX function and get the result data I need. Commented Mar 18, 2013 at 19:11

2 Answers 2

1

Use cURL to retrieve external website data.

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

Comments

0

You can use the PHP readfile function. It requires that allow_url_fopen is set, though.

2 Comments

It's not a file though. It's a reference to a directory that takes an XML query string and produces an XML result. Would this matter?
You sound confusing: Didn't you ask to load XML content from a URL, not from a directory? readfile() is able to load from a URL. Please read the manual page i pasted above.

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.