jquery - Cross Origin Domain Blocking in ajax Image Search API (Google) -


i new ajax. tried using ajax method google image search (deprecated api). reasons client preferring deprecated api custom search. when make request says

cross-origin request blocked: same origin policy disallows reading remote resource @ https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&start=0&imgsz=xlarge,large&q=apple. can fixed moving resource same domain or enabling cors. 

but when call via browser url responds perfect response.

my ajax request

$.ajax({         type : "get",         url : "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&start=0&imgsz=xlarge,large&q=apple",         beforesend : function(xhr) {             xhr.setrequestheader('referer', 'http://www.mydomainexample.com');         },         success : function(result) {             console.log(result)          },         error : function(error) {             console.log(error)          }     }) 

pardon me mistakes. please me out.

ah, cors. source of many weird bugs.

what happens below hood preflight options request, contains origin header. origin domain , protocol on. server returns set of cors headers (access-control-allow-origin , co), tell browser whether should allowed go through request.

if origin , cors headers not match, throws error encountered. there no way around in browser, if want work, you're going have proxy api.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -