0

I have created one RESTful web service which can be accessible using the below url :

http://localhost:8012/getUserData

This RESTful web service is just fetching the Name & Mobile number from database. So i want to show it on the HTML page by calling that API from HTML using Javascript.

I tried below HTML code along with javascript :

<!DOCTYPE html> <html>
    <head>
        <title>Hello jQuery</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script src="hello.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $.ajax({
                    type :"GET"
                    url: "http://localhost:8012/login"
                }).then(function(data) {
                   $('.greeting-id').append(data.id);
                   $('.greeting-content').append(data.content);
                });
            });
        </script>
    </head>

    <body>
        <div>
            <p class="greeting-id">The ID is </p>
            <p class="greeting-content">The password is </p>
        </div>
    </body> </html>

After running this HTML code i got below error :

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

Could anyone help me to sort this problem or if I does anything wrong please correct me

Ala Eddine JEBALI
  • 7,033
  • 6
  • 46
  • 65
sForSujit
  • 987
  • 1
  • 10
  • 24
  • 2
    Duplicate from http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource – Lionel B Mar 22 '17 at 12:35
  • Did you load the html page directly from disk in your browser, or through the web server? An origin of `null` suggests the former, you should probably be using the latter. – James Thorpe Mar 22 '17 at 12:38
  • @JamesThorpe I just start the web service and then directly run above html code in browser – sForSujit Mar 22 '17 at 12:40

0 Answers0