Problems with ajax on the server

0

I have an application on ZF2 on Ubuntu server. One of the controllers is triggered from a ajax request.

Locally, the application works normally. However, when uploading to the server I started having problems: the request is sent as POST, but I can not get the data in the controller, because it arrives as GET and with the data array empty.

Would anyone know what the problem is, since the same code works in the local environment?

No controller o get of data:

$data = $this->getRequest()->getPost()->toArray();
            $request = $this->request;
            $post = array_merge_recursive(
                    $request->getPost()->toArray(), $request->getFiles()->toArray()
            );
            $postData = array();
            $error = array();
            $errSuccess = array();

            //get Query String
            parse_str($post['data'], $postData);

In html I have the following code:

wizard.on("submit", function (wizard) {

            var formData = new FormData();
            formData.append('upload', $('input[type=file]')[0].files[0]);

            var ins = document.getElementById('gallery').files.length;
            for (var x = 0; x < ins; x++) {
                formData.append('gallery[]', $('input[type=file]')[1].files[x]);

            }

            formData.append('data', wizard.serialize());

            $.ajax({
                type: "POST",
                url: '/advertiser/add',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function (resp) {
                    if (resp.response == 1) {
                        $(".create-server-name").text($("#nome_razao").val());
                        wizard.submitSuccess();
                        wizard.hideButtons();
                        wizard.updateProgressBar(0);
                        $.each(wizard.cards, function (name, card) {
                            card.el.find("input").val(); // resets all inputs on a card to ""
                        });
                    } else if (resp.response == 2) {
                        var str = '';
                        for (obj in resp.result) {
                            str += "<li>" + resp.result[obj] + "</li>";
                        }
                        $(".create-server-name").text($("#nome_razao").val());
                        $('#errmsg').html(str);
                        console.log(str);
                        wizard.submitSuccess();
                        wizard.hideButtons();
                        wizard.updateProgressBar(0)
                        $.each(wizard.cards, function (name, card) {
                            card.el.find("input").val(); // resets all inputs on a card to ""
                        });
                    } else {
                        var str = '';

                        $('#errmsgerr').html(resp.result);
                        console.log(str);
                        wizard.submitError();
                        wizard.hideButtons();
                        wizard.updateProgressBar(0)
                    }
                },
                error: function () {
                    wizard.submitFailure();
                    wizard.hideButtons();
                },
            });

        });

The php.ini was not changed after installation. Version php:

PHP 5.6.23-1+deprecated+dontuse+deb.sury.org~trusty+1 (cli) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

This is the .htaccess, which is the same for the 2 environments:

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
    
asked by anonymous 12.10.2016 / 17:14

0 answers