开发者

POST vars suddenly not working through jQuery based AJAX calls

开发者 https://www.devze.com 2023-03-13 20:37 出处:网络
This has been happening since I migrated servers (upgraded to a dedicated server) The AJAX calls, based on jQuery, were working fine for months (if not years) and suddenly they ALL stopped working, a

This has been happening since I migrated servers (upgraded to a dedicated server)

The AJAX calls, based on jQuery, were working fine for months (if not years) and suddenly they ALL stopped working, across all my accounts. You can imagine my panic.

The removefile function looks like this:

 function removefile(filename,folder,targetdiv) { // universal AJAX file removal function. folder MUST include '/' at the beginning for calls. 
    $.post('ajax_removefile.php', {folder:folder, filename:filename },
        function(data){
            if开发者_运维百科(data=='1') {
            $('#'+targetdiv).html(filename+' has been successfully removed.');
            }
            else if(data=='0') {
            $('#'+targetdiv).html(filename+' is already removed - nothing more to remove.');
            }
        });
}

But for some reason, even though Firebug shows a successful registration of the POSt vars being sent, the php file returns completely empty POSt vars. print_r($_POST) or print_r($_REQUEST) returns empty arrays in both cases. If I change the method to a GET mechanism it works - but I'd like to keep it at a POST variable.


First, you can see the raw incoming request in PHP:

$input = file_get_contents('php://input');
var(dump($input);

This will prove that the POST data arrived to PHP or that it was filtered on its way.

Don't forget to set the error_reporting to its max. If you don't want to set this in your php.ini, you can use ini_set() at the beginning of your PHP source, or a .htaccess with php_value (and a integer value).

You probably have a problem with your php.ini. I'm not positive about it, but it may be because your value of post_max_size is far above the 32 bits max integer. Though your PHP seems to be on a 64 bits server, this could be the source of the problem. I suggest you change it from 200000M to 1G. To change this, you can use a .htaccess as above, but then check its effectiveness with ini_get().

It could also be wrong HTTP headers in your AJAX queries, but that seems less likely as nothing changed on this side before the bug appeared.


Oddly enough, the issue was due to a post_max_size that was set too high. Yes, too high. I had to drop it down to what's written in the core php.ini file. I had it set to 20000M across different accounts to just make sure it's practically unlimited, so I had to drop that to 128M (as per the core php.ini max) and it worked.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号