2012-05-17 74 views
0

我使用GET请求通过http打了一个url。我使用下面的代码。从javascript获取http呼叫时失败

onReady: function() { 

     var makeAjaxRequest = function() { 


     var myUrl = encodeURI('http://domainname/VW-MAPP/fgnwasxuyu/10548168/2012-04-11 12:42:36/5555'); 
    Ext.Ajax.request({ 

     method: 'get', 
    url: myUrl, 

    success: function(response)  {  
    alert(''+response.responseText);  
    console.log("response:-"+response.responseText);  },  
    failure: function (response)  {  
    console.log("Failure");  
    console.log("response status:-"+response.status); 
    alert("Failure"); 
} 
      }); 
     }; 



     new Ext.Panel({ 
      fullscreen: true, 
      id: 'content', 
      scroll: 'vertical', 
      dockedItems: [{ 
       xtype: 'toolbar', 
       dock: 'top', 
       items: [{ 
        text: 'XMLHTTP', 
        handler: makeAjaxRequest 
       }] 
      },{ 
       id: 'status', 
       xtype: 'toolbar', 
       dock: 'bottom', 
       title: "Tap a button above." 
      }] 
     }); 
    } 
}); 

我尝试了很多,但得到以下错误

的XMLHttpRequest无法加载// // URLNAME。 Access-Control-Allow-Origin不允许原始位置为null。

如果任何人有任何想法请帮助。

感谢

回答

0

我尝试了两种方法

(1)甩response.xml到地域和访问,我们得到了成功。

(2)通过命令chrome.exe禁止谷歌浏览器安全 - 允许文件访问从文件 - 禁用网络安全,并能够通过GET方法击中网址,并获得成功。

2

同源策略内置浏览器,并阻止您进行AJAX调用比一个服务了当前页以外的任何其他域。

如果响应是JSON,则可以使用JSON-P方法,否则您需要服务器端代理才能进行此调用。

+0

或者,如果他必须访问其他系统,请发送正确的标题。 – ThiefMaster

+0

嗨Diodeus,非常感谢回应。你能告诉我该怎么做才能避免这种浏览器行为?我怎样才能使服务器的ajax调用? – Gendaful

+0

使用PHP,您可以使用CURL,但我不知道您用作服务器的是什么。 –