0

I am trying to grab the JSON from a URL with no luck. If I add the JSON file locally, It will work. I don't know what is it that I am doing wrong. If someone could help me with how I can use JSONP , which I think is the issue in the case, would be very helpful. Here is my code,

$.ajax({
    type: "GET",
    url: "http://srvblrevm98:8099/EVMEmployeeService.svc/GetuserInfo",
    async: false,
    data: {},
    contentType: "application/json",
    processData: true,
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
        var myData = data;
        console.log(data);
    },
    error: function (result) {
        alert("Error");
    }
});
Thomas Sebastian
  • 1,582
  • 5
  • 18
  • 38
  • check the url you are using..is it accessible?? – AkshayJ Jun 03 '15 at 12:05
  • Accessible only in chrome due to some security reasons, they have kept it that way. – Thomas Sebastian Jun 03 '15 at 12:07
  • Don't say `contentType: "application/json",` unless you are posting JSON. Don't say `crossDomain: true,` unless you are using a local URL that is going to redirect to a cross origin one. Don't say `async: false,` ever. – Quentin Jun 03 '15 at 12:08
  • JSONP is a hack to get around the Same Origin Policy. Use CORS instead of you can, that's a much more robust system which is actually designed to let you work around the SOP. – Quentin Jun 03 '15 at 12:09
  • That was me trying hard to make it work. I have the backend dev with me who returns the data completely in a JSON format. Should he do something or is it completely controllable from the client-side? – Thomas Sebastian Jun 03 '15 at 12:09
  • I had previously referred that question. I couldn't understand it. That is why I asked a separate question. I hope someone will show up. – Thomas Sebastian Jun 03 '15 at 12:14
  • The problem is that your question is the same as the duplicate. If there's something you don't understand about the answers, try one of the other ones of the question to see if it explains things in a way you understand. If you still don't get it, then you need to ask a *more specific* question and reference the bits you don't understand. – Quentin Jun 03 '15 at 15:42
  • 1
    The server has to return a JSONP response if you want to parse it as JSONP. – Quentin Jun 03 '15 at 15:43
  • Thanks Quentin. I even suppose that is the issue. That helps. – Thomas Sebastian Jun 04 '15 at 03:59

0 Answers0