POST request on app returns 405 method not allowed

I’m developing an app that performs a POST request to a certain route using ajax. The javascript that performs the request looks like this:

$.ajax({
type: “POST”,
url: “/nextcloud/apps/app/save”,
data: JSON.stringify(files),
contentType: “application/json”,
success: function(data) {
console.log(data);
}
});

While our routes looks like this:
return [
‘routes’ => [
[‘name’ => ‘page#index’, ‘url’ => ‘/’, ‘verb’ => ‘GET’],
[‘name’ => ‘savefile#save’, ‘url’ => ‘/save’, ‘verb’ => ‘POST’]
]
];

and the controller looks like this

class saveFileController extends Controller {
private $userId;

public function __construct($AppName, IRequest $request, $UserId){
	parent::__construct($AppName, $request);
	$this->userId = $UserId;
}

/**
 * @NoAdminRequired
 * @NoCSRFRequired
 * 
 * @param string $files
 */
public function save(string $files) {
    var_dump('we did it!');
    return null;
}

}

But when the request is performed we recieve the error:
POST (url) 405 (Method Not Allowed)

What are we doing wrong here?

The jquery ajax method doesn’t have a type option, it should be method :wink:

$.ajax({
   method: “POST”,
   url: “/nextcloud/apps/app/save”,
1 Like