Wednesday, September 30, 2015

Intel XDK - useful tips

If the screen is a full independent page, you can write the below script to load this screen from other page button click event.

af.ui.loadContent("#uib_Validate_User",false,false,"fade");
      
If the screen is a sub page, you can write the below script to load this screen from other page button click event.

$(":mobile-pagecontainer").pagecontainer("change", "#uib_Validate_User", { reverse: false});

Reading value of the Radio Button group on a button click.

var adVal = $("input:radio[id='af-radio-ad']:checked").val();
        var acVal = $("input:radio[id='af-radio-ac']:checked").val();
        if (adVal=="on")
            alert("Auto driver");
        else if(acVal=="on")
            alert("Auto customer");
        else   
        {
            $("label[id='lblNewUserMobile']").html("Please select");
           
        }

Creating a cookie in intel XDK
        var mobilenum= $("#txtMobile").val();
       
         // 1 is to expire in1 day. put -1 if you don't want cookie to expire
        intel.xdk.cache.setCookie("mobilenum",mobilenum,1);

Remove the cookie

intel.xdk.cache.removeCookie("mobilenum");

Read the Cookie

 var value = intel.xdk.cache.getCookie("mobilenum");


Getting a geocode and passing to web service on click of button

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    }
    }
    function showPosition(position) {
        var lat =   position.coords.latitude ;
        var lang =  position.coords.longitude;
        var url = "http://localhost:62905/MarketFeed.svc/DoWork/" + lat + "/" + lang;
       
        $.ajax ({
         url: url,
         type: "GET",
         dataType: "json",
         success: function(data){ alert("Request succeeded. Data: " ); },
         error: function(xhr) { alert("Request error"); }
        });

 

No comments: