0

Im attempting to pull in an xml feed that I can load up with php and simpleXML and I can view the direct link, but when I try to use jquery and GET it just times out and I never get a response, the error that comes back is undefined.

Here is the code im using

$.ajax({
type: "GET",
url: "myurlishere",
dataType: "xml",
timeout: 1000,
contentType: "text/xml",
success: function(xml) {
       alert("in");
  },
   complete: function(XMLHttpRequest, textStatus) {
               alert(textStatus);
   },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
       alert(errorThrown);
    }
 });

5 Answers 5

2

Is the URL in the same domain as the page with your Javascript in it? If not, then the browser won't let your page access it with simple AJAX.

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

3 Comments

yeah its from a different domain, so im searching google for an xml Same Origin Policy work around. What should I do?
The normal way is to build a PHP script that runs on your server, makes the request to the external resource, and returns the results to you.
0

The code looks o.k. to me. The notable difference between PHP and JQuery, though, is that PHP is executed on your web server, and JQuery in your visitor's browser. Maybe the URL you use is accessible only to the PHP script on the web server.

Does it work when you type in the URL into your browser address bar?

What kind of URL is it? It doesn't start with localhost, does it?

2 Comments

yeah it works when I go straight to it, it does not say localhost , its a link to a feed on a webserver that i can view, and access with php, its just not doing anything when i try to request it with jquery though
Ahh of course, the Same Origin Policy. That won't work, you will need a proxy on your local web server. @Pointy got it right.
0

Often these issues stem from url mixups: e.g. a relative URL is specified, but it's off by 1 directory, etc.

Also -- I notice you're specifying a timeout of 1 second. I don't know what sort of URL you're hitting... is this enough time?

1 Comment

yeah , not sure, im using a direct link to an xml feed on a server that i can view directly if i copy and paste it into the browser. Even after I increase the timeout time I get the same thing
0

Did you tryed

$.load(); 

$("#xml").load("myurlishere/xml.php", {pamameters: 25}, function(data)
{
   alert("Data Loaded"+data);
});

Have a look at http://api.jquery.com/load/

3 Comments

I tried doing this above, and it does the alert for the load, but doesnt show any data, and in firebug the xml feed is still like spinning and timing out
Please post the whole get request from firebug
With which parameters did you called the script above? with myurlishere/xml.php or something else?
0

In the script that you are trying to access... Before you print out any of your XML data, are you outputting XML headers? i.e.:

header("Content-Type:text/xml");

=====

To fix the domain issue, create a .php file on your server like this:

<?php

$xml = file_get_contents("http://www.the_other_domain.com/feed.xml");

echo $xml;

?>

Then point your AJAX call to that, instead.

1 Comment

im not sure I do not have access to what is actually producing the feed, here is what i get when i try to validate it though line 1, column 38: Undefined root element: Response help center <?xml version="1.0" encoding="utf-8"?><Response xmlns:xsi="w3.org .

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.