javascript - How to make an JsonP request using ajax-core + Polymer -
i'm starting webcomponents , trying use polymer , ajax-core ajax request. need make request api, don't know how handle cors problem.
my code looks like.
<link rel="import" href="../polymer/polymer.html"> <link rel="import" href="../core-ajax/core-ajax.html"> <polymer-element name="test-form"> <template> <textarea></textarea> <button on-click="{{buttonclick}}">load</button> <core-ajax id="ajaxsubmit" url="someexternalapi" method="get" response="{{response}}"> </core-ajax> </template> <script> polymer("contact-form",{ buttonclick:function(){ this.$.ajaxsubmit.go(); }, responsechanged:function(oldvalue){ console.log(this.response); } }); </script> </polymer-element>
but way of i'm getting no 'access-control-allow-origin' error.
any ideas?
thank you!
there 2 ways:
- if can have control on backend can enable
cors
- or can use polymer-jsonp (see here example)
Comments
Post a Comment