JQuery $ .post sends vars correctly, but PHP doesn't get anything

I have this jQuery script that sends a username to a password in a PHP file that checks if this user exists and returns a custom JSON object. Works fine in browsers other than IE, but IE fails.

The strangest thing is that IE "firebug" says that everything is in order, but the PHP script does not receive any vars ...

This is the request body:

username = johanderowan & password = 1234

These are request headers (I didn’t take into account several vars for security reasons):

Request = POST / 1.0 / account / login.json HTTP / 1.1
Accept = /
Origin = [DEVURL]
Accept-Language = nl-NL
UA-CPU = AMD64
Accept-Encoding = gzip, deflate
User-Agent = Mozilla / 5.0 (compatible ; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident / 5.0)
Host = [DEVURL]
Content-Length = 66
Keep-Alive Cache-Control no-cache connection

Response body (first three empty arrays: $ _GET, $ _POST and $ _REQUEST):

Array ()
array ()
array ()
{"status": "error", "message": "No username or password.", "HttpCode": 500}

This is a script request:

$('.mobyNowLoginForm form').bind('submit', function(){  
    var username = $(this).find('.username').val();  
    var password = $(this).find('.password').val();  
    $.post('[url]/1.0/account/login.json', {
        username: username,
        password: password
    }, function(response) {
        // do something
    }, "JSON");  
    return false;
});

I have no clue what might be wrong here ...

+3
2

, IE . "/".

: http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

, php:// $_POST vars.

if ($_SERVER['REQUEST_METHOD'] == 'POST' && count($_POST) == 0) {
    $postData = file_get_contents('php://input');
    $postVars = explode('&', $postData);
    foreach ($postVars as $postVar) {
        list($key, $var) = explode('=', $postVar);
        $_POST[$key] = $var;
    }
}
+1

false. , :

$.ajax({
  type: 'POST',
  url: '[url]/1.0/account/login.json',
  dataType: 'json',
  data: {
      username: username,
      password: password
  },
  cache: false,
  success: function() {
      // Do something
  }
});

, !

Edit

URL . .json . .php .

, .php :

header("Content-Type: application/json");
0
source

All Articles