【问题标题】:Ajax Cross Domain not working [duplicate]Ajax跨域不起作用[重复]
【发布时间】:2012-10-09 06:08:22
【问题描述】:

可能重复:
Ajax cross domain call

在这里使用此代码..

   var URLs = new Array();
   var titulo = new Array();

   $.ajax({
     url: 'http://www.example.com.br',
     type: 'GET',                                                    
     success: function(res) {
       headline = $(res.responseText).text();                                                              
       URLs = headline.split(",LK");
       CriaVideos(URLs);                               
    }
   }); 

  function CriaVideos(URLs)
  {                           
   for(var i = 0; i <= 5; i++)
   {
    var aux = new Array();
    aux = URLs[i].split("#");

    titulo.push(aux[0]);
    titulo.push(aux[1]);
    Cria(titulo);
   }                   
  }                                           

 function Cria(titulo)
 {                                                                   
   document.write('<li><div id="frame_video"><a href="TelaVideoWind.php?nome='+       titulo[1]+ '&video=' + titulo[0] + '"><span class="frame_video_img"><img src="img/play.png" width="60px" height="40px" align="middle" style="position: absolute; margin-top: 55px; margin-left: 95px;"/><img src="http:/'+ titulo[0]+ '/i.ytimg.com/vi/hqdefault.jpg" width="250px" height="150px"/></span><span class="frame_video_desc"></span></a></div></li>');                          
 }

它会在标题 document.write 中工作还是在函数之外使用但它不起作用!不知道有没有人可以帮忙!

【问题讨论】:

标签: javascript html ajax


【解决方案1】:

正如 Felix Kling 提到的那样,大多数浏览器都不允许这样的跨域调用。有几种方法可以解决这个问题,比如http://en.wikipedia.org/wiki/JSONP,但这需要你要打的是我相信的 JSONP 服务。

或者,您可以在您使用的任何网络语言中使用代理页面。因此,您可以让一个 php 页面执行服务器到服务器请求,以获取您当前正在向其发送 ajax 请求的页面。然后,您的代理页面可以提供从其服务器到服务器调用到 ajax 调用的内容/响应。

【讨论】:

  • 所以..但是我在同一个域中..我只是想处理这个来自同一个域的字符串并将标题放在数组 document.write 中以创建视频组件!但是他们说只有从一个函数到另一个函数才有可能交易..不知何故我必须得到这个数组并在其他地方使用?或者任何更好的解决方案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-18
  • 1970-01-01
  • 1970-01-01
  • 2013-12-07
  • 2012-03-08
  • 2013-06-22
  • 1970-01-01
相关资源
最近更新 更多