0
votes

I have an ajax call that is working fine on Chrome, FF and Safari but always fail on IE ("success but no data"). I've checked server logs and the right response always triggers but still IE shows empty response and doesn't catch the right 302 http status code. I've tried many combinations and found that when using contentType: "text/html; charset=utf-8" IE does get the response but the problem is that $_POST array is empty since sending POST should be contentType: "application/x-www-form-urlencoded; charset=utf-8"

This is my javascript:



function someFunc() {   
  $.ajax({
    cache: false,
    async: false,
    type: 'POST',
    dataType: 'html',
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
        //contentType: "text/html; charset=utf-8",
    url: myProtocol + myHost + "/mypage.php",
    data: {action: "someAction"},
    success: function( data ) {
        if (data == ""){
            alert("success but no data");
            return;
        }
        // do something...
        return;
    },
    error: function( data ) {
        if (data.status == "302"){
                            // do something...
            return;
        } else {
            // do something...
            return;
        }
    }
});

  return;
}

this is my PHP response (mypage.php):

    

$loginUrl = "someUrl";
header("HTTP/1.1 302 Found");
header("Content-Type: text/html; charset=utf-8");
Header("Content-Length: " . mb_strlen($loginUrl, "8bit"));
header("Connection: close", true);
echo $loginUrl;

Only on IE 7-9 I end up with "success but no data" on other browsers works perfect. any idea? somebody?

Thanks!

2
Tried that as well, no good same result.Itamar Lavender

2 Answers

-1
votes

The problem was with the fact that IE is trying to follow the redirect location which was not what I wanted to do in my JS. the workaround I did was to change the response to 200 OK and make the JS detect if a URL is in response then do something with it:

success: function( data ) {
    if (data.match('http://') || data.match('https://')){
        window.parent.location = data;
        return;
    } else {
            var url = (window.location != window.parent.location) ? document.referrer: document.location;
        window.parent.location = url;
        return;
    }
}
-1
votes

Are you returning Location HTTP header?

header("Location", $loginUrl);