-1

Im trying go access one html page from another.All my html pages hosted in server. My index page is loading without issue. But when trying other pages, I get following error,

XMLHttpRequest cannot load http://localhost:8080/cache/getSite?clientName=bps. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8080' is therefore not allowed access.

Im accessing from the browser like;

http://127.0.0.1:8080/ //for index.html

http://127.0.0.1:8080/doc/clientSiteinfo.html?client=bps //for other pages linked with index.html

I generated my index page with the links for other pages like;

> function loadCustomers(configFile) {          $
>                   .ajax({
>                       type : 'GET',
>                       url : configFile.server + ':8080/cache/getCustomers',
>                       dataType : 'json',
>                       success : function(data) {
>                           var rows = [];
>                           $
>                                   .each(
>                                           data,
>                                           function(id, value) {
>                                               rows
>                                                       .push(' <tr><td><a href="'+configFile.server+':8080/doc/clientSiteinfo.html?client='
>                                                               + id
>                                                               + '">'
>                                                               + id
>                                                               + '</td><td>'
>                                                               + value
>                                                               + '</td><td><button type="button" onclick="resetClient(\''
>                                                               + id+','+configFile.server
>                                                               + '\')">Reset</td></tr> ');
>                                           });
>                           $('#clients_data').append(
>                                   '<tbody>' + rows.join('') + '</tbody>');
>                           $('#clients_data').DataTable({
>                               "pagingType" : "full_numbers"
>                           });
> 
>                       }
>                   });         };
Ratha
  • 9,434
  • 17
  • 85
  • 163
  • Possible duplicate of [Why does my JavaScript get a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error when Postman does not?](https://stackoverflow.com/questions/20035101/why-does-my-javascript-get-a-no-access-control-allow-origin-header-is-present) – CBroe Oct 20 '17 at 01:10
  • @CBroe Firsttime index.page is loading , why then other htmls are not working? Can you provide answer? What im doing here – Ratha Oct 20 '17 at 01:14
  • You are trying to make a cross-domain request, but the target URL does not respond with the correct headers to allow that. If CORS means nothing to you, then go _read up_ on the subject! – CBroe Oct 20 '17 at 01:26

1 Answers1

0

I overcame this issue by setting Access-Control-Allow-Origin header in the jQuery request.

I have written a blog post here

Ratha
  • 9,434
  • 17
  • 85
  • 163