<html> <body> <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script> <script> $(document).ready(function () { $.ajax({ type: 'GET', async: false, contentType: "application/json", url: "http://www.XXX.XXX.in/api/categories",//url:"dir/categories", dataType: "jsonp", //dataType: "jsonp", success: function (data) { $.each(data, function(i,data) { var det="<div>id :"+data.categoryId+" Name "+ data.categoryName+"</div></br>"; $(det).appendTo("#display"); //alert(det); }); alert(data); }, error: function (data) { alert("this is error "+data); } }); }); </script> <div id="display"></div> </body> </html> In the above code I am trying to access the categories json and print the details.
I am doing it in two ways:
I have kept the categories file in dir/ folder and accessing it which shows me result properly.
When I try to access it online it gives me an error: When I give dataType:"json" instead of jsonp I gives following error:
OPTIONS http:// XXX.XXX.in/api/categories 404 (Not Found) XMLHttpRequest cannot load http:// XXX.XXX.in/api/categories. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http:// localhost:8080' is therefore not allowed access. I dont know whether the server has cross platform ref. added.