Safari browser settings truncating POST options

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

Below is the ajax entry I am using -

$.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 debugging purposes, I entered the logs into 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, console logs display something like

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

Any guess why Safari behaves this way, even with the iPad / iPhone and another OS where Safari is used as a browser, I ran into this truncation problem. I also read a post in which people encounter such problems, but in those cases they had a very big request, and on the other hand, just a small request.

Any help?

+8
javascript safari ajax php
source share
1 answer

I checked your code and I had a problem 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 of the result.

In any case, dataType parameter, I got the desired result:

this is a screenshot of the safari console

I also suggest you use a proxy, for example Charles https://www.charlesproxy.com , to see the real result obtained by the PHP script, so you can find out if you have a problem on the javascript side or on the server.

+2
source share

All Articles