0

I have a xml content stored in the location, http://localhost:8080/cleo-primer/rest/elements/search?uid=1&query=facebook

<element-list><element><term>facebook</term><name>Bing Facebook</name></element></element-list>

I am sending a get request

 $.get('http://localhost:8080/cleo-primer/rest/elements/search', { uid: 1, query: request.term }, function(responseData){alert(responseData);});

but this gives me a blank response and when I check using my firebug, it shows XML Parsing Error: no element found Location: moz-nullprincipal:{1e7688d3-7b3c-43ae-9142-5b183a7cbfda} Line Number 1, Column 1: inside XML tab

Da Silva
  • 229
  • 1
  • 7
  • 17
  • What does your xml content look like? – Asciiom Sep 03 '12 at 09:31
  • Ive added it above in the qustion – Da Silva Sep 03 '12 at 09:33
  • Does your XML have a doctype? E.g. - and it needs to be presented as XML with the correct headers/content-type http://www.petefreitag.com/item/381.cfm – Alex Sep 03 '12 at 09:33
  • What is your content type header? – Viktor S. Sep 03 '12 at 09:33
  • @FAngel contenttype header is – Da Silva Sep 03 '12 at 09:35
  • Hm. Meta is an HTML header attribute. Why it is in XML content? – Viktor S. Sep 03 '12 at 09:42
  • 1
    [these headers](https://devcentral.f5.com/weblogs/images/devcentral_f5_com/weblogs/dawn/WindowsLiveWriter/AccelerationABCsFisforFirebug_AB24/FirebugHeaders.jpg) are more important (request/response) – VDP Sep 03 '12 at 09:42
  • @VDP Those headers are present response header is application/xml – Da Silva Sep 03 '12 at 09:46
  • so you can rule that out as the problem ;) where are you calling from? http://localhost:8080 or just http://localhost ? – VDP Sep 03 '12 at 09:48
  • there's your problem ;) solution provided as answer. Can you modify the headers of the backend? (I guess so cause it's running locally) – VDP Sep 03 '12 at 09:49
  • Hm. XML parsing error because of denied cross domain request?... If that does not solve the problem - show us content of Request tab in firebug(should be near XML tab) – Viktor S. Sep 03 '12 at 09:51
  • the request header has contents, Accept */* Accept-Encoding gzip, deflate Accept-Language en-us,en;q=0.5 Connection keep-alive Host localhost:8080 Origin http://localhost Referer http://localhost/testRun User-Agent Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0.1 – Da Silva Sep 03 '12 at 09:53
  • Oh. Sorry. Not request tab. There should be Response tab. Suppose it will be next to Headers tab. Must show plain response text. – Viktor S. Sep 03 '12 at 09:55
  • blank response, he said in the question. So yes it is the source. I can't tell if there aren't any other problems yet but that issue is where he should start.. – VDP Sep 03 '12 at 09:56
  • I see nothing in response you provided. As the last option I would try to see a response with a [Fiddler](http://www.fiddler2.com/fiddler2/). There could be something in your response that breaks firebug completely and does not allow to see response text. Also - does it works in other browsers? – Viktor S. Sep 03 '12 at 10:05

1 Answers1

1

You are doing a cross origin call that is not allowed. You are calling from: http://localhost to http://localhost:8080. The call isn't executed and there will be NO response. Chrome/Safari will show an error like this in the console:

XMLHttpRequest cannot load http://targeturl Origin http://localhost is not allowed by Access-Control-Allow-Origin.

More info: http://en.wikipedia.org/wiki/Same_origin_policy#Origin_determination_rules

If you can make modifications to the back-end, making it send the right headers, will fix your problem... (Access-Control-Allow-Origin yourdomain or Access-Control-Allow-Origin * for allow all)

More info: http://enable-cors.org

A couple of other options to be complete...

  • If you use apache: You can use an apache proxy to forward (map) location on port 8080 to a different port (like the default port 80) I've posted a question/answer about it a while ago...
  • You could also resort to jsonP (it's not xml but json) using a technique that is loading your resources through a scripttag, you can load json if you're json is adapted to it. (wrapped it a callback function call)
  • If you can't do that either your only option is a proxy script. A proxy script is a sort of middleware. You make a request to the script the script gets the data, and returns it to you. For example php proxy. You can make the same thing in asp, jsp, flash or even java applet.
Community
  • 1
  • 1
VDP
  • 6,340
  • 4
  • 31
  • 53