Click here to Skip to main content
13,800,416 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I have the following :
<html>
<body>
    <button id="json">json</button>
    <script src="Scripts/jquery-2.0.3.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#json').click(function () {
                alert('json');
                $.getJSON("http://www.hpgloe.com/json/getrec/?lat=37.234&lon=-122.234", {},
                function (data) {
                    //alert("here");
                    alert(data);
                }).fail(function (jqXHR, textStatus, errorThrown) { alert("fail " + errorThrown); });
            });
        });
    </script>
</body>
</html>

But it just gives a useless message :
fail error
Posted 8-Nov-13 22:29pm
Comments
   
Have you tried with some other URL?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

try this


<html>
<body>
    <button id="json">json</button>
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#json').click(function () {
                alert('json');
               /* $.getJSON("http://www.hpgloe.com/json/getrec/?lat=37.234&lon=-122.234", {},
                function (data) {
                    //alert("here");
                    alert(data);
                }).fail(function (jqXHR, textStatus, errorThrown) { alert("fail " + errorThrown); });
            */
			
			$.ajax({
					  url: 'http://www.hpgloe.com/json/getrec/?lat=37.234&lon=-122.234',
					  dataType: 'jsonp',
					  success: function(data){
						 alert(data);
					  }
					});
					});
        });
    </script>
</body>
</html>
  Permalink  
v2
Comments
Mehdi Gholam 9-Nov-13 6:44am
   
Thanks that worked on the original URL, but I had to add this on my server:
Response.AppendHeader("Access-Control-Allow-Origin", "http://localhost:56551");

for the call I was making :

url: 'http://localhost:8080/testing/function',// 'http://www.hpgloe.com/json/getrec/?lat=37.234&lon=-122.234',
dataType: 'json',
success: function (data) {
alert(JSON.stringify(data));
}

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.181214.1 | Last Updated 9 Nov 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100