2

I have a simple jquery app with a rails backend, and I am trying to run it in aws cloud9 and make several requests to the backend. Here is some sample code.

var previous = $("#previous");
previous.on('click', function() {  
    $.get("/games", function(data) {  
        console.log(data) 
     })
})  

When I click the previous button on the page, I get this 404 error :jquery-3.2.1.min.js:4 GET https://vfs.cloud9.us-east-2.amazonaws.com/games 404 ()

I know that the route is correct, leading me to believe that there must be some other url or parameter to use when making requests in aws cloud9. Any help is greatly appreciated!

adam tropp
  • 674
  • 7
  • 22
  • how you checked your url format means is there any other directory path missing or not? – Dipak Jan 19 '18 at 18:02
  • Means does your file pointing proper place of URL – Dipak Jan 19 '18 at 18:03
  • If I run the rails server and go to /games, this is the url I am sent to: – adam tropp Jan 19 '18 at 18:07
  • what is rails url format? – Dipak Jan 19 '18 at 18:08
  • https://ee55715a523f4af8bae9f5467daf644d.vfs.cloud9.us-east-2.amazonaws.com/games. However, If I try to use that whole thing as the parameter for the get request, I get this error: – adam tropp Jan 19 '18 at 18:09
  • because somehow url pointing is an issue – Dipak Jan 19 '18 at 18:09
  • jquery-3.2.1.min.js:4 GET https://ee55715a523f4af8bae9f5467daf644d.vfs.cloud9.us-east-2.amazonaws.com/games 499 () (anonymous) @ tictactoe.js:19 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3 index-test.html:1 Failed to load https://ee55715a523f4af8bae9f5467daf644d.vfs.cloud9.us-east-2.amazonaws.com/games: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://vfs.cloud9.us-east-2.amazonaws.com' is therefore not allowed access. The response had HTTP status code 499. – adam tropp Jan 19 '18 at 18:09
  • I am used to running a localhost server, so usually with rails I can just navigate to localhost:3000/route_name – adam tropp Jan 19 '18 at 18:10
  • oh ok, Adam, it means that you should allow accessing this URL in your rails application. so you should set "Access-Control-Allow-Origin" with your cloud url in rails – Dipak Jan 19 '18 at 18:11
  • and when you send request from cloud to the local server it requires to add "access control" header in your application as per my best knowledge. – Dipak Jan 19 '18 at 18:13
  • Cool thank you! Much appreciated! – adam tropp Jan 19 '18 at 18:15
  • did it work for you? – Dipak Jan 19 '18 at 18:16

0 Answers0