Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 70
Registered: ‎04-08-2011
My Device: BB 4 and BB 5.0
My Carrier: BB Curve

AJAX Problem

[ Edited ]

Hi, I'm using "6.0.0.313 (9800)" simulator to test the application, but ajax it not working on it, I'm getting RSS feed from source website, I have tried by changing the datatype to "text/xml" but no luck. and I'm pulling data using default port 80.

 

I have defined the access url in config.xml with attribute subdomain=true

 

 

I'm using simple ajax function:

 

 

$.ajax
    ({
           type: "GET",
           url: _url,
           data: '',
           dataType: 'xml',
           success:
           function(result)
           {
             $('#spinner').hide();
                callback(result);
           },
           error:
           function (data, status, e)
           {
                //alert("error:"+e);
                $('#spinner').hide();
           }
    });

 

 

How can I resolve it?

 

Thanks

Developer
Posts: 70
Registered: ‎04-08-2011
My Device: BB 4 and BB 5.0
My Carrier: BB Curve

Re: AJAX Problem

[ Edited ]

somebody help me how to resolve it, this is a very basic problem.

I'm using PHP on server side and set the response header to header('Content-type: text/xml');

 

 

Thanks

Developer
Posts: 70
Registered: ‎04-08-2011
My Device: BB 4 and BB 5.0
My Carrier: BB Curve

Re: AJAX Problem

[ Edited ]

I have replaced it with conventional ajax but still its not working:

 

what's wrong with the code?

 

 

 function ServerCall1(_e,_dtype,_url,callback) {
   


    var xmlHttpReq = false;
    var self = this;
    self.xmlHttpReq = new XMLHttpRequest();
    self.xmlHttpReq.open('POST', 'http://www.example.com/torch/'+_url, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'text/xml');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
   
            callback(self.xmlHttpReq.responseXML);
        }
    }
    self.xmlHttpReq.send('w=1');
};

Developer
Posts: 37
Registered: ‎12-24-2010
My Device: Tour
My Carrier: Verizon

Re: AJAX Problem

 

Are you trying to post data or get data? If you are trying to get data, try this instead;

 

var httpRequest = new XMLHttpRequest();

httpRequest.open('GET', '<enter the url>', true); 
httpRequest.send(null); 
httpRequest.onreadystatechange = function() { 
  if (httpRequest.readyState == 4) { 
   var str = String(httpRequest.responseText);
  } 
};

 

 

 

Developer
Posts: 70
Registered: ‎04-08-2011
My Device: BB 4 and BB 5.0
My Carrier: BB Curve

Re: AJAX Problem

[ Edited ]

Thanks, Yes I am getting data only,Its coming on readystate 4 without any data, In browser its working fine.

 

 

 

 

 

 function ServerCall1(_e,_dtype,_url,callback){

    var xmlHttpReq = false;

    xmlHttpReq = new XMLHttpRequest();
   
    xmlHttpReq.open('GET', 'http://www.example.com/zubair/torch/'+_url, true);
    xmlHttpReq.setRequestHeader('Content-Type', 'text/xml');
    xmlHttpReq.onreadystatechange = function() {
       
        if(xmlHttpReq.readyState == 4){

            callback(xmlHttpReq.responseXML);
            topHeader.putData("<h1>success</h1>");
        }
    }
   xmlHttpReq.send(null);
};
Developer
Posts: 70
Registered: ‎04-08-2011
My Device: BB 4 and BB 5.0
My Carrier: BB Curve

Re: AJAX Problem

[ Edited ]

I have installed this application to test, but it also giving "No response from server, connection timeout"

 

untitled.PNG

 

http://208.74.204.192/t5/Web-and-WebWorks-Development/Sample-Code-RSS-Reader/ta-p/589890

 

 

Thanks

Developer
Posts: 70
Registered: ‎04-08-2011
My Device: BB 4 and BB 5.0
My Carrier: BB Curve

Re: AJAX Problem

My applications can't access internet, the browser application can access internet.

I'm using 6.0.0.313 (9800)
Retired
Posts: 518
Registered: ‎07-18-2011
My Device: Bold
My Carrier: Rogers

Re: AJAX Problem

Hi Zubair,

 

Can you quickly double check that you've whitelisted all the domains you're accessing on the server using <access> elements in your config.xml



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Developer
Posts: 70
Registered: ‎04-08-2011
My Device: BB 4 and BB 5.0
My Carrier: BB Curve

Re: AJAX Problem

[ Edited ]

see the config:

 

 

 <?xml version="1.0" encoding="utf-8"?> 
 <widget xmlns=" http://www.w3.org/ns/widgets"
         xmlns:rim="http://www.blackberry.com/ns/widgets"
         version="2.0"
         rim:header="RIM-Widget: rim/widget">

 <author href="http://www.example.com/"
         rim:copyright="Copyright 1998-2011 test">test</author>
   <rim:navigation mode="focus" />
   <name>test</name>

   <description>
 test
   </description>


  
   <icon src="icons/appicon.png"/>
   <icon src="icons/appfocus.png" rim:hover="true"/>

   <rim:cache maxCacheSizeTotal="2048" maxCacheSizeItem ="256" />

   <content src="index.htm">
   </content>

   <feature id="blackberry.ui.dialog"/>
   <access uri="http://www.example.com" subdomains="true"/>
   <access uri="http://www.test.com"     subdomain="true"/>
   <access uri="http://www.prphotos.com"         subdomain="true"/>
   <access uri="http://feeds.starpulse.com"     subdomain="true"/>
   <access uri="http://horoscopeservices.co.uk" subdomain="true"/>

  

   <license>
     Example license
     Copyright (c) 2011 My Corp.
     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
     BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
     ACTION OF CONTRACT, INSULT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     SOFTWARE.
   </license>

 </widget>
Regular Contributor
Posts: 83
Registered: ‎04-29-2011
My Device: 9300 Curve
My Carrier: TIM

Re: AJAX Problem

I put the domain "*" into my config.xml and check "subdomain" as true. So that way, it will access to all websites, right?
Márcio Saeger - Software Engineer, Softwell Solutions