• Register
0 votes
77 views

Problem :

I am getting following error
cross-origin request blocked: the same origin policy disallows reading the remote resource at
6.9k points

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 :

38.6k points

Related questions

0 votes
2 answers 1.4K views
1.4K views
Problem : Uncaught domexception: blocked a frame with origin from accessing a cross-origin frame:I am trying to load the <iframe> in my HTML page and want to access the elements within it using the Javascript, however when I want to execute my code, I face the below ... || iframe.contentWindow.document; var mytarget = mydoc.getElementById("my-target-id"); mytarget.innerHTML = "Found it!"; }); });
asked Dec 4, 2019 alecxe 7.5k points
0 votes
1 answer 317 views
317 views
Problem : I have spent over the 10 hours in finding the exception or the special character to find in the code but I am unable to find it. I have already checked every similar messages in here. I am facing below error: Syntaxerror: json.parse: unexpected character at line 1 ... my form after that I am sending all the inputs to the main.js to validate it. So, I am just looking for the third-eye.
asked Dec 23, 2019 alecxe 7.5k points
0 votes
1 answer 5 views
5 views
I have a function foo which makes an asynchronous request. How can I return the response/result from foo? I tried returning the value from the callback, as well as assigning the result to a local variable inside the function and returning that one, but none of those ways actually ... response; // return response; // <- I tried that one as well }); return result; // It always returns `undefined` }
asked Nov 10 Han Li 710 points