1

I am trying to get a basic $resource request via angularjs. I am running this on my local computer.

However, I get a 404. A simple get request on the browser loads the json. Here is the request shown by chrome devtools. (Question: why is the request mode: OPTIONS? Could that be the problem?)

Request URL:http://example.com/api/rentable_properties.json
Request Method:OPTIONS
Status Code:404 Not Found

Here is my controller that is attempting to make the request:

'use strict';

angular.module('adminApp')
.factory('Property', function($resource)
{
  return $resource('http://example.com/api/rentable_properties.json/:propertyId');
});

angular.module('adminApp')
  .controller('PropertiesCtrl', function ($scope, Property, $location) {
    $scope.properties = Property.query()  
Karan
  • 14,824
  • 24
  • 91
  • 157

2 Answers2

1

The answer here is that your browser is running into a cross domain issue

See http://metajack.im/2010/01/19/crossdomain-ajax-for-xmpp-http-binding-made-easy/ for an explanation and Why am I getting an OPTIONS request instead of a GET request? for a question basically the same as yours.

Community
  • 1
  • 1
JSager
  • 1,420
  • 9
  • 18
1

As mentioned by @JSager, the problem was a cross domain issue.

Since I had control over the server side (running a Rails server), I had to change the server to it to receive cross-site requests.

In my case, I had to install a gem and follow it's instructions.

https://github.com/cyu/rack-cors

This fixed the issue for me. No changes made on the Angularjs based app.

Karan
  • 14,824
  • 24
  • 91
  • 157