0

I am using <iron-ajax> like as :

<iron-ajax id="dataAjax" url={{url}} method="POST" handle-as="json" params="{{getParam()}}" on-response="createResp" last-response="{{ajaxResponse2}}"></iron-ajax>

When i Check in Network tab in Chrome, response is coming, but because of following error createResp does not execute.

XMLHttpRequest cannot load http://...URL.... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

I tried with this:

_handleError:function(event){
        console.log(event.detail.request.xhr.response); //null
      }

but i got null, but in network tab i am able to see the response.

And also status is 200

Can anyone help me how to get the response.

Mandeep Singh
  • 1,287
  • 14
  • 34

1 Answers1

1

There are plenty questions about this. What you are looking for is Cross browser origin. for example:

How to solve No 'Access-Control-Allow-Origin' in polymer-project?

Allow cross origin - iron-ajax - Polymer

"No 'Access-Control-Allow-Origin' header is present on the requested resource"

I had same problem at the beginning. We are using JAVA Spring for rest API and we had to configure that server so it will accept requests from my url ( i am using virtual hosts because we have dynamic Ips in company).

You can try to use CORS but still with the same problem:

In order for this to work, the server must also enable credentials by setting the Access-Control-Allow-Credentials response header to “true”.

Anyway using iron-ajax is not effective in your case. You should specify your own XMLHTTPRequest

Community
  • 1
  • 1
Kuba Šimonovský
  • 2,013
  • 2
  • 17
  • 35
  • "iron-ajax don't support" — If it didn't support it, it wouldn't complain about the permissions that allow it being missing from the server. – Quentin Mar 02 '17 at 14:32
  • @Quentin ye sorry, didn't realize that. i was writing that article for a while and you are right. I just forgot to remove it :) – Kuba Šimonovský Mar 02 '17 at 15:07
  • that can't happen at server side, but i am getting response 200 with data, but due to error in polymer , i am not able to show it – Mandeep Singh Mar 03 '17 at 12:50
  • then i suggest you to try your own xmlhttprequest.. i have never heard about this. if you get 'Access-Control-Allow-Origin' error there is no chance to get also data. are you sure you are looking to the same request? can you screen network tab in developer tools in chrome? – Kuba Šimonovský Mar 03 '17 at 13:47