Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   PHP, PERL, MySQL, JavaScript (https://forum.antichat.xyz/forumdisplay.php?f=37)
-   -   Отправка HTTP запросов через ВКонтакте API [AJAX] (https://forum.antichat.xyz/showthread.php?t=155582)

GlooK 10.11.2009 22:47

Отправка HTTP запросов через ВКонтакте API [AJAX]
 
Не актуально!

Хочу, используя API ВКонтакте, отсылать GET и POST запросы.

Но получается не очень...

Вот часть index.html (находится на локальной тачке, все пути на скрипты изменены на абсолютные)
Код:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" id="vkontakte">
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1251" />
<title>В Контакте | Добро пожаловать</title>
<link rel="stylesheet" href="http://vkontakte.ru/css/rustyle.css?37" type="text/css" />
<script src="http://vkontakte.ru/js/common.js?63"></script>
<script type="text/javascript" src="http://vkontakte.ru/js/lang0_1000.js?722"></script>
<script type="text/javascript" src="http://vkontakte.ru/js/lib/ui_controls.js?23"></script>
<link rel="stylesheet" href="http://vkontakte.ru/css/ui_controls.css?10" type="text/css" />
<link rel="shortcut icon" href="http://vkontakte.ru/images/favicon.ico" />
<script src="http://vkontakte.ru/js/niftycube.js?1"></script>
<script type="text/javascript">
var base_domain = 'http:/';
var links_visibility = 0;
var css_versions = {privacy_css: 5};

(function(){
        var loadFn = function(){
                Nifty("ul.tabs a", "small top");
                Nifty("ul.buttonRow a", "small");
                Nifty("div.leftAd","small transparent");
                Nifty("div.selPad","small transparent");
                Nifty("div.myPad", "small transparent");
                placeholderSetup('qinput');
        };
        //addEvent(window, 'load', loadFn);
        onDomReady(loadFn);
})();
</script>
...
...

Если на этой странице я вставляю в URL:
javascript:Ajax.Get({url:'mail.php',query:{act:'wr ite',to:1},onDone: function(ajaxObj,responseText){}});
то запрос не проходит. Если этот запрос сделать на странице http://vkontakte.ru/index.php, то запрос отлично проходит.

В чем проблема?

P.S. Часть common.js (ВК)
Код:

...
...
function Ajax(onDone, onFail, eval_res){
  var _t = this;
  this.onDone = onDone;
  this.onFail = onFail;
  var tram = null;
  try { tram = new XMLHttpRequest(); }
  catch(e) { tram = null; }
  if (!tram) {
    try { if(!tram) tram = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch(e) { tram = null; }
  }
  if (!tram) {
    try { if(!tram) tram = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch(e) { tram = null; }
  }

  var readystatechange = function(url, data) {
      if(tram.readyState == 4 ) {
      if(tram.status >= 200 && tram.status < 300) {
        if(eval_res) parseRes();
        if( _t.onDone ) _t.onDone(extend(_t, {url: url, data: data}), tram.responseText);
      } else {
        if( _t.onFail ) _t.onFail(extend(_t, {url: url, data: data}), tram.responseText);
      }
    }
  };

  var parseRes = function(){
    if(!tram || !tram.responseText)return;
    var res = tram.responseText.replace(/^[\s\n]+/g, '');

    if(res.substr(0,10)=="<noscript>")
    {
      try{
        var arr = res.substr(10).split("</noscript>");
        eval(arr[0]);
        tram.responseText = arr[1];
      }catch(e){
        debugLog('eval ajax script:' + e.message);
      }
    }else{}
  };
  this.get = function(u, d, f){
    tram.onreadystatechange = function(){ readystatechange(u, d); };
    f = f || false;
    var q = (typeof(d) != 'string') ? ajx2q(d) : d;
    u = u + (q ? ('?'+q) : '');
    tram.open('GET', u, !f);

    tram.setRequestHeader("X-Requested-With", "XMLHttpRequest");
    tram.send('');
  };
  this.post = function(u, d, f){
    tram.onreadystatechange = function(){ readystatechange(u, d); };
    f = f || false;
    var q = (typeof(d) != 'string') ? ajx2q(d) : d;
    try {
      tram.open('POST', u, !f);
    } catch(e) {
      debugLog('ajax post error: '+e.message);
    }
    tram.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    tram.setRequestHeader("X-Requested-With", "XMLHttpRequest");
    tram.send(q);
  };

 }
...
...


PaCo 10.11.2009 23:01

Цитата:

В чем проблема?
В настройках безопасности, через XMLHttpRequest нет возможности напрямую обращаться к другому хосту.

GlooK 10.11.2009 23:03

Цитата:

Сообщение от PaCo
В настройках безопасности, через XMLHttpRequest нет возможности напрямую обращаться к другому хосту.

Т.е. я вообще не смогу через AJAX (не используя API ВК) сделать запрос на другой сайт?

biophreak 12.11.2009 23:39

Да, пока что не сможешь...максимум через хаки...погугли XDomainRequest.
Ну, или если сервак умеет JSONP, то через него.


Время: 15:54