Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari browser truncating POST parameters

My code works absolutely fine on other browsers than Safari 6.1.2 on Mac OS Lion.

Below is the ajax post that I use -

$.ajax({
     type: 'POST',
     dataType: 'text/html',
     url:"/MyProxy.php",
     data:{"server":"mydomain.com", "user":"vijay", "passd":"highly@secret"},
     error: function(data) {
         console.log(data);
         alert("Failure - "+data);
         return;
     },
     success: function(data) {
         console.log("Success - "+data);
         parseInformation(data);
     }
 });

Also for debug purpose, I have entered logs on my PHP server code

header('cache-control: no-cache');

function getRealPOST() {
    $pairs = explode("&", file_get_contents("php://input"));
    $vars = array();
    foreach ($pairs as $pair) {
        $nv = explode("=", $pair);
        $name = urldecode($nv[0]);
        $value = urldecode($nv[1]);
        $vars[$name] = $value;
    }                   
    return $vars;
} 

echo "-------";         
var_dump($_POST);           
echo "-------";             

print_r(getRealPOST()); 

In Safari on console logs it shows something like -

-------array(2) {
  ["userName"]=>
  string(5) "vijay"
  ["passwd"]=>
  string(4) "hig"
}
-------Array
(
    [

serverAdd] => mydomain.com
    [userName] => vijay
    [passwd] => hig
)

Any guess why only Safari is behaving in such way, even with iPad/iPhone and other OS where Safari is used as browser, I am facing this truncation problem. I have also read post where people are facing such issues, however, in those cases, they were having very large request, mine on other hand is just small request.

Any help?

like image 294
VijayKumar Avatar asked Mar 04 '14 11:03

VijayKumar


1 Answers

I tested your code and I had an issue with the dataType: 'text/html' parameter of your request. Usually there is no need to specify it, jQuery is smart enough to understand the format the received outcome.

Removing the dataType parameter anyway I received the desired output:

this is the screenshot of Safari console

I would also suggest you to use a proxy like Charles https://www.charlesproxy.com to view the real output obtained by the PHP script so you can figure out if you have a problem on javascript or server side.

like image 87
Igor S Om Avatar answered Nov 03 '22 23:11

Igor S Om