0

I've some jQuery code sending data through an AJAX call to a PHP script.

Data consists of an object with two properties.

One of the properties is a string, obtained by JSON.strinfigy(arrayofobjects) an array of objects. Each object in arrayofobjects contains 3 properties, each being a simple string. The number of objects in arrayofobjects is variable based on some user actions.

The problem is: when arrayofobjects exceeds the number of 25 objects the AJAX call fails and returns 403 Forbidden, so any debug is impossible.

It seems like the string resulting from JSON.stringify and sent through AJAX ovverides a maximum length.

The web server is Apache2 running on Ubuntu 18.04. Not using any PHP framework.

What I have tried:

  • Apache mod_security module is not active
  • In php.ini: display_errors = On, log_errors = On and error_reporting = E_ALL
  • Set write permissions for every user on apache2/error.log
  • Regular working apache2/error.log, but no trace of AJAX-related issue, no trace of any 403 error
  • URL of called script is correct
  • It's not a cross-domain call
  • File permissions are OK since the script is called successfully in other instances and when arrayofobjects contains less than 25 elements
  • I can access the called page directly through http
  • Increased max_input_vars value in php.ini

The structure of AJAX call:

$.ajax({
url: "ajax/called_page.php",
type: 'post',
data: {action: "post_duty", content: JSON.stringify(arrayofobjects)},
dataType: "json",
success: function(data) {
 do some DOM manipulation
}, error: function() {
 alert('Contact webmaster');
}
  • In your ajax : `error: function (jqXHR, textStatus, errorThrown) { console.log(jqXHR); console.log(textStatus); console.log(errorThrown); }` can help debugging – Cid Sep 25 '19 at 10:11
  • Possible duplicate of https://stackoverflow.com/questions/36666256/jquery-ajax-call-results-in-error-status-403 – Casper Sep 25 '19 at 10:12
  • If you are using a php framework, such as Symfony, you should check the logs of that framework too (Symfony logs are in `/var/logs` – Cid Sep 25 '19 at 10:13
  • @Casper this is not a CORS request – Cid Sep 25 '19 at 10:14
  • How do you know: "when arrayofobjects exceeds the number of 25 objects the AJAX call fails" is true? – HerrWalter Sep 25 '19 at 10:14
  • @Cid I'm not using any PHP framework – Adriano Di Cara Sep 25 '19 at 10:18
  • @HerrWalter this post triggered me to think about the array length, so I tried to extend `arrayofobjects` up until 25 elements, that's when the call fails. https://stackoverflow.com/questions/10211620/json-stringify-output-is-1023-character-why – Adriano Di Cara Sep 25 '19 at 10:20
  • @Cid tried debugging using your code, but it's not returning anything more than what I get using browser developer tools – Adriano Di Cara Sep 25 '19 at 10:22
  • Please check your file/folder permission. – Casper Sep 25 '19 at 11:48

0 Answers0