Search code examples
ajaxjquerycross-domainjsonp

jquery ajax success not working


I got simple ajax call i could not get why it is not running success method despite the fact that chrome developer tools show that it is getting the response for the request.

$( document ).ready(function() {
    var url_API="http://moviesapi.herokuapp.com/cinemas/find/"+"PL15RH";
    $.ajax({
        type: 'GET',
        url: url_API,
        dataType: "jsonp",
        crossDomain:true,
        success: function (response) {             
            alert(1);
        }

    });
});

Solution

    1. The API doesn't support jsonp. You're getting 500 (Internal Server Error).

    2. It does support JSON, but you're getting the classic No 'Access-Control-Allow-Origin' header is present on the requested resource CORS error. You need to explicitly send the Access-Control-Allow-Origin header on your heroku API:

    Header property:

    Access-Control-Allow-Origin: *
    

    A more verbose solution: "No 'Access-Control-Allow-Origin' header is present on the requested resource"