0

I am trying to retrieve data from 3rd party xml api through jquery ajax call. But it is showing Access Control Allow Origin CORS error. After some twiking I a getting ERR_CONNECTION_RESET error on Chrome.

This is the the Api link from where I am trying to retrieve data

http://202.61.117.90/GRIPS/ChallanDetails/query.do?GRN_NO=192021225551499528

This is my own server url to access the api http://103.240.91.230:8080/CRM/checkApi.do?method=checkApi

Below is the html/jquery code i am using

<script>
$(document).ready(function(){
  $.ajax({
  type: "GET" ,
  url: "http://202.61.117.90/GRIPS/ChallanDetails/query.do?GRN_NO=192021225551499528" ,
    headers: {  'Access-Control-Allow-Origin': 'http://202.61.117.90/*' },
    dataType: "xml" ,
  success: function(xml) {

  $(xml).find('GRIPS_EPAYMENT').each(function(){
   var grnNo = $(this).find('GRN_NO').text();
    var grnDate = $(this).find('GRN_DATE').text();
   var brnNo = $(this).find('BRN_NO').text();

    $("#grndate").append(grnDate);  
   $("#brnno").append(brnNo);  
     });    
  }      
     });
    });
    </script>

I am using tomcat 8.5 and added following filter in web.xml

 <filter>
     <filter-name>CorsFilter</filter-name>
     <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
    </filter>
   <filter-mapping>
     <filter-name>CorsFilter</filter-name>
      <url-pattern>/*</url-pattern>
     </filter-mapping>

Note: when I am calling same api from my local server - it works fine

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Indrajit
  • 1
  • 2
  • The `Access-Control-Allow-Origin` header has to be set on the server in the response. Not on the client in the request – derpirscher Jul 14 '21 at 16:58
  • Not sure where to put on server - as this jquery script is used to call the api. No jquery is used on the sender server – Indrajit Jul 15 '21 at 06:07
  • There must be something what creates the response in the server. Add the cors header there. Doesn't matter it it's js or something else. You may even be able to define fixed cors headers in tomcat. Have a look at the docs. – derpirscher Jul 15 '21 at 06:31

0 Answers0