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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Chris StanyonWebDevCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.