简体   繁体   English

从javascript进行http调用时出现故障

[英]Getting failure while making http call from javascript

I am hitting a url over http with GET request. 我正在使用GET请求在http上打网址。 I am using below code. 我正在使用下面的代码。

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."
            }]
        });
    }
});

I tried a lot but getting below error 我尝试了很多但是低于错误

XMLHttpRequest cannot load //URLNAME//. XMLHttpRequest无法加载// URLNAME //。 Origin null is not allowed by Access-Control-Allow-Origin. Access-Control-Allow-Origin不允许使用null。

Please help if any one has any ideas. 如果有任何想法,请帮助。

Thanks 谢谢

The Same Origin Policy is built into the browser and prevents you from making AJAX calls to any other domain other than the one serving up the current page. 同源策略内置于浏览器中,可防止您对提供当前页面的域之外的任何其他域进行AJAX调用。

If the response is JSON, you can use the JSON-P method, otherwise you need a server-side proxy to make this call. 如果响应是JSON,则可以使用JSON-P方法,否则需要服务器端代理才能进行此调用。

I tried two approaches 我尝试了两种方法

(1) Dumped the response.xml to the local domain and access and we got the success. (1)将response.xml转储到本地域并访问,我们获得了成功。

(2) Disable google chrome security by the command chrome.exe --allow-file-access-from-files --disable-web-security and were able to hit the url over GET method and got success. (2)通过命令chrome.exe --allow-file-access-from-files --disable-web-security禁用谷歌浏览器安全性,并且能够通过GET方法点击网址并获得成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM