Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple REST call from Javascript

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.

like image 706
Ajax3.14 Avatar asked Sep 10 '26 22:09

Ajax3.14


1 Answers

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.

like image 195
ram Avatar answered Sep 13 '26 12:09

ram