简体   繁体   中英

how to access api in blackberry 10 using html5 and javascript

I am new to blackberry 10. I am developing an app using html5 and javascript via phonegap.I am unable to fetch the data from the api when i run the application in ripple emulator. Unexpectedly i am getting xmlhttp status -> 0.

when i hit the api url on browser it works fine. Don't know what is exact problem.

Please assist me how to access api in blackberry10?

I am attaching my code here.

HTML code :

<div data-role="page" id="homePage">
    <div data-role="header">
        <div>
            <div class="choose-city-head-A">
                <span ><img src="images/m.png" height="70%" style="margin-top:12px;margin-left:45%;" /></span>
                <span style="float:right; margin-top:25px; margin-right:20px;"><img src="images/close.png" height="40%" /></span>
                <span style=" float:right;margin-right:20px; margin-top:25px;"><img src="images/help.png" height="40%" /></span>
            </div>
            <div class="choose-city-head-B">
                <h2> Choose City </h2>
            </div>
        </div>
    </div>
    <div data-role="content">
        <div id="home_data" ></div>
    </div>
    <div data-role="footer" class="choose-city-head-A" data-position="fixed">
        <img src="images/prev_button.png" style="margin-left:90px;" />
        <img src="images/favourities.png" style="margin-left:60px;" />
        <img src="images/sms.png" style="margin-left:60px;" />
        <img src="images/next.png" style="margin-left:60px;" />
    </div>
</div>

javascript code :

var xmlhttp = new XMLHttpRequest();

function showHome()
{
    xmlhttp.open("GET", "url", true);
//  xmlhttp.setRequestHeader("Content-Type","text/xml");
    xmlhttp.send(null);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            alert(xmlhttp.status); //status i am receiving is 0
            if (xmlhttp.status == 200)
            {
                var responsexml=xmlhttp.responseText;
                var xmlDoc=xmlhttp.responseXML;
            }
        }
    }
}

Your code is correct..

I have also faced this problem ealier Try to install Emulator again..Hope it will works as it worked for me...!!

Cheers!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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