jquery - Loading static JSON from local FS or remote rails server -


i've looked @ several questions in , been lead in couple of directions have not bore fruit.

here jquery/html:

<html> <head>     <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> </head> <body>     <script>     $(document).ready(function(){         alert ("hi");          $.getjson("/users/rabdelaz/desktop/actfast/pm-md.json",function(result){ //this version 1         //$.getjson("http://172.28.101.197:3000/tests.json",function(result){    //this version 2             alert ("file good");         }); });</script> </body> </html> 

first, tried open -a "google chrome" --args --allow-file-access-from-files (i'm on os x) before opening file. used version 1as shown in code above part. gave me this:

xmlhttprequest cannot load file:///users/rabdelaz/desktop/actfast/pm-md.json. cross origin requests supported protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource. 

this made me think should try host file on rails server have running.

so tried serve static json rails server located on machine. used version 2 above. gave me this:

xmlhttprequest cannot load http://172.28.101.197:3000/tests.json. no 'access-control-allow-origin' header present on requested resource. origin 'null' therefore not allowed access. 

just completeness, here controller serves json:

@@data = file.read("/home/rabdelaz/pm-md.json") # /tests # /tests.json def index   render :text => @@data.to_s, :callback => params['callback'] end 

i'm happy ditch rails server here thought help. use deciding on direction go in.

you try adding rails method

 headers['access-control-allow-origin'] = '*'  headers['access-control-request-method'] = '*' 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -