简体   繁体   中英

Error 403 Forbidden when making post call with jquery ajax call on same domain

I have a webpage( mainmenu.php ) with a javascript function as script in the webpage. The java script function name is : statusHistoryUpdate(status)

This function does a ajax post call to a php file located on the same domain as my webpage. Here is the function code :

                    function statusHistoryUpdate(status)
                    {


                           var data = {
                                reg_no: selectedRegNo,
                                status: status,
                                progress_id : selectedProgress
                            };
                            data = $(this).serialize() + "&" + $.param(data);
                          //alert(data);
                          $.ajax({
                          type: "POST",
                          dataType: "json",
                          url: "../db/statusHistory.php", //Relative or absolute path to response.php file
                          data: data,
                          beforeSend: function(){

                            $('#loading').toggle();
                            //$("#submitbutton").html( "<button id='buttonsubmit' class='btn btn-primary btn-lg btn-block' type='submit' value='Register' disabled> <span class='spinner-border spinner-border-md'></span>Loading..</button>");
                          },
                          success: function(data) {

                              getData();
                          },
                          complete: function(){
                            //$('.ajax-loader').css("visibility", "hidden");
                            $('#loading').toggle();

                          },
                           error: function(xhr, status, error) {
                            alert(xhr.responseText);
                          }
                        });
                    }

You will see my url that I am posting to is url: "../db/statusHistory.php"

This function is called using a button in mainmenu.php .

<button id="'.$progress_id.'" type="button" class="btn btn-primary btn-sm btn-block" onclick="updateStatus('.$progress_id.',\''.$status.'\',\''.$reg_num.'\')">Update Status</button>

All of this worked up until this weekend something changed and now when this post call is executed it gives me an error 403 Forbidden , you dont have permission to access /db/statusHistory.php

This is the alert in the error: part in the ajax call :

在此输入图像描述

I do not know what is causing this, I have checked permissions, I have created a new php file to post to but it still gives me the same error.

I am hosting on a shared hosting server,using php, jquery/3.4.0. I have only access to the shared hosting panel "CPanel" not the linux server.

Here is screen shots of my hosting directory and permissions. My mainmenu.php is in directory phplogin , mainmenu.php makes a post call to statusHistory.php and it is in the directory db

Public html directory : 在此输入图像描述

phplogin Directory : 在此输入图像描述

db Directory : 在此输入图像描述

What should I be doing differently for my post call to work? As I said it did work for about a month and just stopped...

Any help would be appreciated.

More Screenshots chrome developer tools :

Network tab : 在此输入图像描述

在此输入图像描述 在此输入图像描述 在此输入图像描述

如果之前有效,您应该检查您的.htaccess文件,该文件位于您网站的根目录中。

I have been struggling for 2 days now trying to figure out what is the problem, it turns out the problem was mod_security I disabled mod_security for my domain and my problem was resolved, I will contact my hosting company and ask them to properly do the setup.

Not sure why it just started happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM