read JSON values using $.ajax

Hi I am trying to run this following code to read the JSON values.

I am getting 200 ok message but it only error code is executed.

what is wrong with this code?

var _formURL = 'http://www.json-generator.com/api/json/get/bOAWgfEMuq?indent=2';

	//call for API
	$.ajax({
	  type: 'POST',
	  url: _formURL,
	  dataType: 'jsonp',
    data: {},
	  contentType:'application/json; charset=utf-8',
	  success: function(data) {
	    validateResponsedata (data);
	  },
	  error: function(data) {
	    validateResponsedata (data);
	  }          
	});

	var validateResponsedata = function (data) {
	 alert(data.responseText);
	};

Open in new window


Any help appreciated.

I want to read the items inside the JSON.

Thanks
Perumal_RMAsked:
Who is Participating?
 
Chris StanyonConnect With a Mentor Commented:
The problem you have is because of the mixed content (secure vs non-secure). IE allowes this but most other browsers don't. Your Fiddle is running on HTTPS but the AJAX URL is non-secure. Change the AJAX URL to https and you'll find it will work as expected:

var _formURL = 'https://www.json-generator.com/api/json/get/bOAWgfEMuq?indent=2';
1
 
ste5anSenior DeveloperCommented:
Read the doc. The data Parameter contains data, not a response class instance. Thus its

alert(JSON.stringify(data, null, 2));

Open in new window

instead of

alert(data.responseText);

Open in new window

Cause there is no responseText property in your data.

E.g.
<html>
    <head>
        <script src="jquery-3.1.0.min.js" type="text/javascript"></script>
    </head>
    <body>
        <script>
            var _formURL = 'http://www.json-generator.com/api/json/get/bOAWgfEMuq?indent=2';
            $.ajax({
                type: 'POST',
                url: _formURL,
                dataType: 'jsonp',
                contentType:'application/json; charset=utf-8',
                success: function(data) {
                    validateResponsedata (data);
                },
            error: function(data) {
                validateResponsedata (data);
                }
            });

            var validateResponsedata = function (data) {
                alert(JSON.stringify(data, null, 2));
            };
        </script>
    </body>
</html>

Open in new window


p.s. btw, post concise and complete examples..
0
 
Perumal_RMAuthor Commented:
complete example on fiddle.
https://jsfiddle.net/vLvy82eg/#&togetherjs=nolAyjJflf
Run it on IE, you will see what i want (values from JSON), chrome displays error 404.
could this be a work around i need to figure out why not working on chrome?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.