Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following :
XML
<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
Comments
Have you tried with some other URL?

1 solution

try this


HTML
<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>
 
Share this answer
 
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)



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