Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Error: XMLHttpRequest cannot load http://google.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:50339' is therefore not allowed access. The response had HTTP status code 405.
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="js/jquery-1.12.3.min.js"></script>
<script type="text/javascript" src="js/advajax.js"></script>

    <script type ="text/javascript">

      
        function doOnlineCheck() {
            $.ajax({
                type:"POST",
                url: 'http://google.com',
                success: function (data) {
                    alert('Connection.');
                },
                error: function (data) {
                    alert('No Connection.');
                }
            });
        }
    </script>
    
</head>
<body>
    <div id="status">
        <p id="state">
        <input type="button" />
        </p>
    </div>  
</body>
</html>


What I have tried:

My code is
Posted
Updated 18-Apr-16 20:29pm
v8

1 solution

Hello,

You are trying to make a request to a domain outside of your application domain, for which the browsers blocks, if not from same origin for security reasons and is valid too. You are trying to make a Cross Domain Request.
For this request, your application needs to be CORS prevented, just like POSTMAN is.
Try adding
JavaScript
crossDomain: true,
   dataType: 'jsonp',

to your ajax call properties and check.
I hope that works
You can follow the below link:
AJAX Cross Domain | Cross-Origin Request | jQuery CORS[^]

Update:
Edit fiddle - JSFiddle[^]

Thanks
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 19-Apr-16 4:39am    
5
Ashwini Dhale 20-Apr-16 2:35am    
thank you for reply
Ashwini Dhale 20-Apr-16 2:36am    
Now I get error :


?callback=jQuery1123033…_1461171908492&gws_rd=cr,ssl&ei=wSIXV4m_HcicugSZgJCoCg:1 Uncaught SyntaxError: Unexpected token <

Alert:No internet connection
Passion4Code 20-Apr-16 2:37am    
Check for the syntactical error once.
Passion4Code 20-Apr-16 2:38am    
Try manually setting call back once. Please check the link in my answer (updated)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900