开发者

Extjs: load external url contents as a plain/text

开发者 https://www.devze.com 2023-03-27 19:08 出处:网络
How can I load url contents like XML or JSON as a plain/text into a variable?I don\'t wanna use JsonStore or XMLStore, I want 开发者_如何学编程to load the contents as a text.Looking at http://www.senc

How can I load url contents like XML or JSON as a plain/text into a variable?

I don't wanna use JsonStore or XMLStore, I want 开发者_如何学编程to load the contents as a text.


Looking at http://www.sencha.com/learn/legacy/Manual:Core:Ext.Ajax shouldn't you just be able to write the result into a variable?

var res = false;
Ext.Ajax.request({
    url : 'ajax.php' , 
    params : { action : 'getDate' },
    method: 'GET',
    success: function ( result, request ) { 
        res = result.responseText;
    } 
});

The example was lifted from the docs page.


External URL through Ajax requests are not possible. Initially when Ajax was developed. It was pretty much possible but later on due to security issues it was abandoned. You can try ajax in raw format.


    var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function() {
          if ( xhr.readyState == 4 ) {
            if ( xhr.status == 200 ) {
              document.body.innerHTML = "GOT ACCESS";
            } else {
              document.body.innerHTML = "ERROR";
            }
          }
        };
        xhr.open("GET", "yourPage.php", true);
        xhr.send(null);

Try changing the yourPage.php url to some external site. You will get error in response. https://developer.mozilla.org/En/HTTP_Access_Control. Read this article for more info on Cross-site HTTP calls.

0

精彩评论

暂无评论...
验证码 换一张
取 消