Zend app function/service Catch ajax POST request as GET request

285
March 15, 2017, at 10:54 PM

I have an Zend App with a service:

public function getSiniestroAction(){
  $request = $this->getRequest();
  if ($request->isPost()) 
  { 
    //get object and return as JSON
  }else{
    error_log (print_r($request, TRUE), 3, 'debug_php.log');
    return $this->redirect()->toRoute('bienvenida');        
  }
}

In a view on certain button clicked i call my ajax POST request, but this i catched as a GET request... weird???

jquery ajax request:

$.ajax({
  url: '/sccr/public/get-siniestro',
  type: 'POST',
  data: { 
    'no_code': $('#code').val(),
  },
  dataType: "json",
  cache: false,
  success: function(msg){
    console.log(JSON.stringify(msg));           
  },
  error: function(request, error) {
    console.log('Error!, datail:' + error);
    console.log('Request: ' + JSON.stringify(request));
  }
});

For some reason it is being receive as a GET request (reading my php log), this is my PHP log from line:

error_log (print_r($request, TRUE), 3, 'debug_php.log');

debug_php.log

    Zend\Http\PhpEnvironment\Request Object
(
    [baseUrl:protected] => 
    [basePath:protected] => 
    [requestUri:protected] => /get-siniestro?callback=jQuery220043698793728138363_1489588464882
    [serverParams:protected] => Zend\Stdlib\Parameters Object
        (
            [storage:ArrayObject:private] => Array
                (
                    [REDIRECT_STATUS] => 200
                    [HTTP_HOST] => IP:8085
                    [HTTP_CONNECTION] => keep-alive
                    [HTTP_ACCEPT] => text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01
                    [HTTP_X_REQUESTED_WITH] => XMLHttpRequest
                    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
                    [HTTP_REFERER] => http://IP:8085/administrador/crear-solicitud
                    [HTTP_ACCEPT_ENCODING] => gzip, deflate
                    [HTTP_ACCEPT_LANGUAGE] => es-ES,es;q=0.8
                    [HTTP_COOKIE] => PHPSESSID=feqqj6idebdgas0pi36oj2jp51
                    [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
                    [SERVER_SIGNATURE] => <address>Apache/2.4.7 (Ubuntu) Server at IP Port 8085</address>
                    [SERVER_SOFTWARE] => Apache/2.4.7 (Ubuntu)
                    [SERVER_NAME] => IP
                    [SERVER_ADDR] => IP2
                    [SERVER_PORT] => 8085
                    [REMOTE_ADDR] => IP3
                    [DOCUMENT_ROOT] => /var/www/zf/public
                    [REQUEST_SCHEME] => http
                    [CONTEXT_PREFIX] => 
                    [CONTEXT_DOCUMENT_ROOT] => /var/www/zf/public
                    [SERVER_ADMIN] => [no address given]
                    [SCRIPT_FILENAME] => /var/www/zf/public/index.php
                    [REMOTE_PORT] => 49554
                    [REDIRECT_QUERY_STRING] => callback=jQuery220043698793728138363_1489588464882
                    [REDIRECT_URL] => /get-siniestro
                    [GATEWAY_INTERFACE] => CGI/1.1
                    [SERVER_PROTOCOL] => HTTP/1.1
                    [REQUEST_METHOD] => GET
                    [QUERY_STRING] => callback=jQuery220043698793728138363_1489588464882
                    [REQUEST_URI] => /get-siniestro?callback=jQuery220043698793728138363_1489588464882
                    [SCRIPT_NAME] => /index.php
                    [PHP_SELF] => /index.php
                    [REQUEST_TIME_FLOAT] => 1489588468.328
                    [REQUEST_TIME] => 1489588468
                )
        )
    [envParams:protected] => Zend\Stdlib\Parameters Object
        (
            [storage:ArrayObject:private] => Array
                (
                )
        )
    [method:protected] => GET
    [allowCustomMethods:protected] => 1
    [uri:protected] => Zend\Uri\Http Object
        (
            [validHostTypes:protected] => 27
            [user:protected] => 
            [password:protected] => 
            [scheme:protected] => http
            [userInfo:protected] => 
            [host:protected] => IP
            [port:protected] => 8085
            [path:protected] => /get-siniestro
            [query:protected] => callback=jQuery220043698793728138363_1489588464882
            [fragment:protected] => 
        )
    [queryParams:protected] => Zend\Stdlib\Parameters Object
        (
            [storage:ArrayObject:private] => Array
            (
                [callback] => jQuery2200436987937281386363_1489588464882
            )
    )
[postParams:protected] => 
[fileParams:protected] => 
[version:protected] => 1.1
[headers:protected] => Zend\Http\Headers Object
    (
        [pluginClassLoader:protected] => Zend\Http\HeaderLoader Object
            (
                [plugins:protected] => Array
                    (
                        [accept] => Zend\Http\Header\Accept
                        [acceptcharset] => Zend\Http\Header\AcceptCharset
                        [acceptencoding] => Zend\Http\Header\AcceptEncoding
                        [acceptlanguage] => Zend\Http\Header\AcceptLanguage
                        [acceptranges] => Zend\Http\Header\AcceptRanges
                        [age] => Zend\Http\Header\Age
                        [allow] => Zend\Http\Header\Allow
                        [authenticationinfo] => Zend\Http\Header\AuthenticationInfo
                        [authorization] => Zend\Http\Header\Authorization
                        [cachecontrol] => Zend\Http\Header\CacheControl
                        [connection] => Zend\Http\Header\Connection
                        [contentdisposition] => Zend\Http\Header\ContentDisposition
                        [contentencoding] => Zend\Http\Header\ContentEncoding
                        [contentlanguage] => Zend\Http\Header\ContentLanguage
                        [contentlength] => Zend\Http\Header\ContentLength
                        [contentlocation] => Zend\Http\Header\ContentLocation
                        [contentmd5] => Zend\Http\Header\ContentMD5
                        [contentrange] => Zend\Http\Header\ContentRange
                        [contenttransferencoding] => Zend\Http\Header\ContentTransferEncoding
                        [contenttype] => Zend\Http\Header\ContentType
                        [cookie] => Zend\Http\Header\Cookie
                        [date] => Zend\Http\Header\Date
                        [etag] => Zend\Http\Header\Etag
                        [expect] => Zend\Http\Header\Expect
                        [expires] => Zend\Http\Header\Expires
                        [from] => Zend\Http\Header\From
                        [host] => Zend\Http\Header\Host
                        [ifmatch] => Zend\Http\Header\IfMatch
                        [ifmodifiedsince] => Zend\Http\Header\IfModifiedSince
                        [ifnonematch] => Zend\Http\Header\IfNoneMatch
                        [ifrange] => Zend\Http\Header\IfRange
                        [ifunmodifiedsince] => Zend\Http\Header\IfUnmodifiedSince
                        [keepalive] => Zend\Http\Header\KeepAlive
                        [lastmodified] => Zend\Http\Header\LastModified
                        [location] => Zend\Http\Header\Location
                        [maxforwards] => Zend\Http\Header\MaxForwards
                        [origin] => Zend\Http\Header\Origin
                        [pragma] => Zend\Http\Header\Pragma
                        [proxyauthenticate] => Zend\Http\Header\ProxyAuthenticate
                        [proxyauthorization] => Zend\Http\Header\ProxyAuthorization
                        [range] => Zend\Http\Header\Range
                        [referer] => Zend\Http\Header\Referer
                        [refresh] => Zend\Http\Header\Refresh
                        [retryafter] => Zend\Http\Header\RetryAfter
                        [server] => Zend\Http\Header\Server
                        [setcookie] => Zend\Http\Header\SetCookie
                        [te] => Zend\Http\Header\TE
                        [trailer] => Zend\Http\Header\Trailer
                        [transferencoding] => Zend\Http\Header\TransferEncoding
                        [upgrade] => Zend\Http\Header\Upgrade
                        [useragent] => Zend\Http\Header\UserAgent
                        [vary] => Zend\Http\Header\Vary
                        [via] => Zend\Http\Header\Via
                        [warning] => Zend\Http\Header\Warning
                        [wwwauthenticate] => Zend\Http\Header\WWWAuthenticate
                    )
            )
        [headersKeys:protected] => Array
            (
                [0] => cookie
                [1] => host
                [2] => connection
                [3] => accept
                [4] => xrequestedwith
                [5] => useragent
                [6] => referer
                [7] => acceptencoding
                [8] => acceptlanguage
            )
        [headers:protected] => Array
            (
                [0] => Zend\Http\Header\Cookie Object
                    (
                        [encodeValue:protected] => 1
                        [storage:ArrayObject:private] => Array
                            (
                                [PHPSESSID] => feqqj6idebdgias0pi36oj2jp51
                            )
                    )
                [1] => Zend\Http\Header\Host Object
                    (
                        [value:protected] => IP
                    )
                [2] => Array
                    (
                        [name] => Connection
                        [line] => Connection: keep-alive
                    )
                [3] => Array
                    (
                        [name] => Accept
                        [line] => Accept: text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01
                    )
                [4] => Array
                    (
                        [name] => X-Requested-With
                        [line] => X-Requested-With: XMLHttpRequest
                    )
                [5] => Array
                    (
                        [name] => User-Agent
                        [line] => User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
                    )
                [6] => Array
                    (
                        [name] => Referer
                        [line] => Referer: http://IP/administrador/crear-solicitud
                    )
                [7] => Array
                    (
                        [name] => Accept-Encoding
                        [line] => Accept-Encoding: gzip, deflate
                    )
                [8] => Array
                    (
                        [name] => Accept-Language
                        [line] => Accept-Language: es-ES,es;q=0.8
                    )
            )
    )
[metadata:protected] => Array
    (
    )
    [content:protected] => 
)

The service is returning the data correctly, but as you cans see, when i ask is is a POST request the code take the else statement and enter in the log file.

Rent Charter Buses Company
READ ALSO
Multiple Custom Markers with Individual Info Windows, Click Events, and IDs with Google Maps API

Multiple Custom Markers with Individual Info Windows, Click Events, and IDs with Google Maps API

I have created a map with custom markers using Google maps APISpecifically, I followed their tutorial here

344
How to number each element of an array

How to number each element of an array

I am trying to number each element of an array, I have used for loop but does not work

319
Page Transition fade-out with js

Page Transition fade-out with js

I need to add a fade-out transition when users go out from Splash page to Home page

264