Problem sending AJAX request with headers on Blackberry Webworks

拜拜、爱过 提交于 2019-12-10 16:28:44

问题


I am developing a Blackberry webworks application and I am having trouble with an AJAX request that I am making to a server. I am learning HTML/Javascript/AJAX on the fly, so excuse any beginner mistakes. Basically, formatted HTTP requests are made to the server, which returns JSON objects that I use in the application. I am using AJAX to make the requests without any kind of framework. Most requests do not have to be authenticated, and those are returning just fine. However, to access a directory part of the server, a username and password are encoded and sent as a header with the XMLHTTPRequest. when I try and add the header, the request is sent, but I never get anything back. The readyState property is set to 1, but never goes beyond that. I know the server works fine, because I did the same thing for iPhone, and it worked.

Here is the relevant code:

function grabFromServer(httpRequest){   
httpConnection = new XMLHttpRequest();
var me = this;
httpConnection.onreadystatechange=function(){
    alert(httpConnection.readyState);
    if(httpConnection.readyState==4){
        me.processResponseText(httpConnection.responseText);
    }
};
httpConnection.open("GET", httpRequest,true);

if(this.request == "company" || this.request == "property" || this.request == "individual"){
    var authorized = this.checkCredentials();
    if(!authorized){
        //ask for username pword
    }
    //here, add credentials
    httpConnection.setRequestHeader("Authorization", "Basic : ODI5ZGV2bDokY19kdXN0Ym93bA==");
}
httpConnection.send();

}


回答1:


Your code appears to be good. Have you added an entry in your config.xml file to allow access to your domain? You should see an entry for something like <access subdomains="false" uri="http://data.mycompany.com/"/>. To make any HTTPRequests to an external website from a WebWorks application, you have to add an entry to "whitelist" domain like this.

If you're using the eclipse plugin, open up the config.xml file, click the Permissions tab at the bottom, and click "Add Domain".



来源:https://stackoverflow.com/questions/5585407/problem-sending-ajax-request-with-headers-on-blackberry-webworks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!