Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Ajax call gets 403 Forbidden

Started by Muut Archive 10 years ago · 3 replies · 2035 views
10 years ago

I'm doing an ajax call to a small file located in the plugins folder. But when doing so I get the error [HTTP/1.1 403 Forbidden]

When I place the file in the root folder instead, it works.
Is there a way to change permissions so I can place the file with my plugin in my plugins-folder and call it there? Perhaps make an exception for just this file to be called?

This is a small file that will make periodic checks to check if any files and folders have changed, and if so, update the page.

Problem number 2 is that I don't really know what namespace and such I have to place in this single ajax file to be able to access the built in functions of GRAV like Uri and such.

Right now the file is simply printing out text to test the call, but I want it to also be able to access the deeper functions of grav and still remain a small file since it will be periodically called in quite short intervals.

Thank you for you time.

10 years ago

I found the solution to half my problem by looking in the .htaccess file and commenting out the file RewriteRule ^(user)/(.*)\.(txt|md|yaml|php|pl|py|cgi|twig|sh|bat)$ error [F]

But I would like to keep this rule and only make an exception for my specific file located in user/plugins/check.php

10 years ago

Typically you shoudln't be calling .php even via ajax.. call it with .json extension in the url and convert data to json with the |json_encode filter.

10 years ago

@rhukster
call it with .json extension
I have a php file that returns data from database in .json format. How would my ajax call look like?
-------------- request = $.ajax({ url: "/data.php", type: "post", data: data, dataType: 'json', success: function (response) {}, error: function (request, status, error) {} }); ----------------
Of course this is giving 403 forbidden error, unless I put my php file in root folder.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1354 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4064 9 years ago
Archive · by Muut Archive, 9 years ago
1 2951 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago