locked
urgent--> issue with connecting API through JQuery Ajax Method RRS feed

  • Question

  • User-1719701746 posted

    Hi,

    I am not able to connect with an API through Jquery.... plz help....

    <html>
      <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, 
                  target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
      </head>
      <body>
        <div class="app">
          <h1> hello</h1>
          <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
            <input type="button" value="Say hello to me"  />
            <button>Click me</button>
          </div>
        </div>
        <!--<script type="text/javascript" src="phonegap.js"></script>
        <script type="text/javascript" src="js/index.js"></script>-->
        <!--<script type="text/javascript" src="js/soapclient.js"></script>-->
        <script type="text/javascript" src="../www/js/jquery-1.2.3.min.js"></script>
    
        <script type="text/javascript">
         <!--// app.initialize();-->
          
          var url='http://ota.airindia.in/BBservice/Service.asmx?op=HelloWorld';
          $(document).ready(function(){
          $("button").click(function(){
          alert("1");
          $.ajax
          ({
          method: "POST",
          url: url,
          data: {name:,"Riya"},
          contentType: "application/json; charset=utf-8",
          dataType: "json",
    
          }).done(function( msg )
          {
          alert( "Data Saved: " + msg );
          });
    
          });
          });
    
    
        </script>
      </body>
    </html>



    Thursday, June 13, 2013 1:42 AM

Answers

  • User281315223 posted

    This error is occurring because you are attempting to perform an AJAX Request to a target that is not of the same origin / domain (which is not allowed for obvious security reasons).

    Does the Service / API that you are attempting to reach have any specific kind of documentation that you may want to consider reviewing or suggested methods of accessing it (because if you are receiving these Cross-Domain issues, you aren't going to be able to use AJAX to handle this).

    Check out this blog post on CORS (Cross Origin Resource Sharing) for a bit more information about what exactly is going on here and a possibly solution to fix your issue.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 17, 2013 8:15 AM

All replies