Programmers learn & share
0 votes
46 views

Problem :

I am getting following error
cross-origin request blocked: the same origin policy disallows reading the remote resource at
by (6.9k points)   | 46 views

1 Answer

0 votes

Solution :

Please note the JSONP or "JSON with padding" is a communication technique used in JavaScript programs which are running in web browsers to request data from a server which is in a different domain, something got  prohibited by the typical web browsers because of the same-origin policy. Also JSONP takes advantage of the fact that browsers are not enforcing the same-origin policy on script tags. So for JSONP to work, a server must know how to reply with JSONP-formatted results. Please note JSONP does not work with JSON-formatted results.

 $.ajax({
        type: "GET",
        url: 'http://www.oxfordlearnersdictionaries.com/search/english/direct/',
        data:{q:idiom},
        async:true,
        dataType : 'jsonp',   //you can use jsonp for cross origin request
        crossDomain:true,
        success: function(data, status, xhr) {
            alert(xhr.getResponseHeader('Location'));
        }
    });

Further Readings :

by (36.1k points)  
2,204 questions
2,603 answers
59 comments
241 users