javascript - Syncrhonous Cross-Domain AJAX request -


suppose following directory structure:

/web     example.html     example.js /example.json 

i open example.html browser , runs example.js, tries load data in example.json synchronously using following call:

$.ajax({url: "file:///example.json",         datatype: "json",         async: false,         success: function(data) {             console.log(data)         },         error: function(request, status, error) {             console.log(request);             console.log(status);             console.log(error);         } }); 

this results in error message "access restricted uri denied" , error code 1012. far, have taken @ access restricted uri denied“ code: ”1012 - cross domain ajax request , access restricted uri denied code: 1012. first link suggested use jquery's getjson method, method works asynchronously. second link suggests sort of jsonp callback, haven't been able understand how these work.

note problem goes away if move example.json /web/example.json, avoid due circumstances of actual problem (what presented here simplification of actual problem).

edit: trying jsonp code, still running same error:

$.ajax({url: "file:///example.json",     datatype: "jsonp",     success: function(data) {         console.log(data)     },     error: function(request, status, error) {         console.log(request);         console.log(status);         console.log(error);     } }); 

by default cross-domain ajax requests not allowed. need permission other server using cors, or can use jsonp.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -