简体   繁体   中英

Unable to make a javascript get to a ruby on rails XML page

I have an application running on Ruby on Rails that returns an XML page like this

<?xml version="1.0" encoding="UTF-8"?>
<list>
  <item title="Professor" href="437">name1</item>
  <item title="Professor" href="1">name2</item>
  <item title="Professor" href="2">name3</item>
  <item title="Professor" href="438">name4</item>
  <start>1</start>
  <end>4</end>
</list>

which I get by accessing

http://localhost:3001/people.xml

When, in the browser, I get this page everything is fine but if I use this following code in jquery

$.get('http://localhost:3001/people.xml', function(data) {
  console.log(data);
});

I get, in firebug, the following error:

XML Parsing Error: no element found Location: moz-nullprincipal:{ca8a9975-1761-4999-a65a-fe7d0a810762} Line Number 1, Column 1:

What can it possibly be ?

Thanks!

The problem was that the port where I was making the get request (3000) was different from the one who had the data (3001), thus receiving this error.

This happens because one is not able to make ajax get's to a website running in a different domain or port.

The solution passed by making the request in ajax to my own controller (in port 3000) and, in the controller, making the request to the port 3001 and then returning it back.

Keep in mind that in ajax you can only make requests to the same domain, in the same port !

Hope it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM