S
S
serious9112015-04-08 12:07:51
PHP
serious911, 2015-04-08 12:07:51

Cross-domain AJAX Vkontakte?

Hello.

There was a problem with adapting a simple iframe of the Vkontakte game for IE8+, namely with ajax requests.
The application is loaded via IFRAME from the site sub.domain.ru/game.php. AJAX requests are sent from a script (JavaScript) using jQuery to sub.domain.ru/api.php. In Chrome/FF/Safari/Opera everything works without problems. In IE8/9, Ajax requests simply don't work or get blocked (no response).

Code for sending requests:


$.ajax({
type: "POST",
async: isAsync,
url: URL,
data: params,
success: function(answer) {
....
}
});


Added headers for cross-domain requests in PHP:

header('Content-Type: text/html; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET');


Enabled CORS in JavaScript:

$.support.cors = true;

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Evgeny Petrov, 2015-04-08
@Petroveg

Probably because older IEs use XDomainRequest .
There is also written about the solution .

S
serious911, 2015-04-08
@serious911

The problem turned out to be completely different and it is related to cookies... Cookies are set for the user during "authorization" and for all ajax requests of the user, the server checks these cookies to understand that this is the "correct" user:
setcookie("uid", $uid, time()+3600*24, '/');
.....
For some reason, cookies are not set in IE - probably this is due to IFRAMEs... The PHP script sets cookies from the sub.domain.ru/game.php domain, and then they are sent along with the request to sub.domain.ru/api.php where they are checked.

I
Igor Kravchenko, 2015-04-08
@kravasuper

stackoverflow.com/questions/3362474/jquery-ajax-fa...

A
Alexander, 2015-04-08
@shendel

Where did you see a cross-domain request here?
Does the script from sub.domain.ru/game.php send Ajax to sub.domain.ru/api.php? If yes, then this is not a cross-domain
The problem is in scripts that are not friendly with IE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question