ajax giving blank response

前端 未结 1 1994
滥情空心
滥情空心 2021-01-27 07:33

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

<         


        
相关标签:
1条回答
  • 2021-01-27 08:11

    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.
    0 讨论(0)
提交回复
热议问题