3

I am trying to call my service from here http://diningphilospher.azurewebsites.net/api/dining

using below javascript,

$.ajax(
{
    type: "GET",
    dataType: "json",
    url: "http://diningphilospher.azurewebsites.net/api/dining/",
    success: function (data) 
    {
        alert(data);
    }
});

But I am getting error relating cross origin. I see people suggest using JSONP but I guess my server does not support JSONP. I studied CORS and could not understand the head or tail of it. I would like to know the way around to read the JSON that sits in different domain.

5
  • 1
    What do you not understand about CORS? What server are you running? I pretty sure it can handle json. Commented Apr 21, 2013 at 22:44
  • @Musa, Currently if i use this I get CORS error. How to fix that. I was told to add a Access-Control-Request-Allow-method as part of request. I cannot find a simple working example. All i see is W3C docs. Is there a links showing how to enable CORS in client side through examples Commented Apr 21, 2013 at 23:25
  • 1
    Try adding this Access-Control-Allow-Origin: * http header. Commented Apr 21, 2013 at 23:31
  • 1
    url is outputting xml not json or jsonp. As far as server supporting jsonp... jsonp is just text output that is parsed by browser as script Commented Apr 21, 2013 at 23:58
  • @charlietfl great catch. you are right, I am now working to remove the default formatter from xml to json.hope it works Commented Apr 22, 2013 at 0:25

1 Answer 1

1

I hope this should work:

$.ajax(
{
    type: "GET",
    dataType: "jsonp",
    url: "http://diningphilospher.azurewebsites.net/api/dining/",
    success: function (data) 
    {
        alert(data);
    }
});

Or just add/append ?callback=? along with your cross-domain url.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.