0

In my phonegap project, I wanna use the jquery template, I tried an example :

This is my page:

<html>  
<head>
...
    <script type="text/javascript" src="jquery.min.js"></script>        
    <script type="text/javascript" src="jquery.tmpl.js"></script>       
</head>
<body>    
    <script type="text/x-jQuery-tmpl" id="app_products">
        <div class="productsLIST">
            <div>
                <div class="image">
                    <div id='${productID}'></div>
                    <div >
                        <div class="image-detail"> <img src="${imgPath}" alt="Product" class="img-responsive"> </div>
                    </div>            
                    <div>
                        <p class="name">${product_name} </p>
                        <span class="price">${price} DT</span>
                    </div>
                </div>
            </div>
        </div>     
    </script>

    <div id="content"></div>    

    <script>
         var ws_url = "http://192.168.0.25:8080/services";
        $.ajax({
            type: 'GET',
            url : ws_url+'/request/getJsonData/125',
            data : {},
            dataType: 'json',
            error : function(jqXHR, exception) {},
            success : function(xhr){
                var jsonData = JSON.parse(JSON.stringify(xhr));
                if(jsonData != null && jsonData.length) {
                    $.each(jsonData, function(index, item) {
                        var _options = {};
                        $("#app_products").tmpl(item, _options).appendTo("#content");                   
                    });
                }       
            } 
        });
    </script>
</body>

This example doesn't work on an android device. I don't know why. This code works on a web browser!

senior
  • 2,196
  • 6
  • 36
  • 54
  • Yes it should work. But remember that cordova/phonegap injects some javascript libs that can interfer. – Ravenix Nov 25 '16 at 13:44
  • Yes you can.Is your android device connected to the same network whatever your computer is connected? – Homen Nov 25 '16 at 13:46
  • That could be the issue, because it's trying to connect to your network. – Ravenix Nov 25 '16 at 13:47
  • yes it's connected to the same network. others WS work fine on my device. – senior Nov 25 '16 at 13:49
  • @Ravenix, "cordova/phonegap injects some javascript libs that can interfer." I'm newbie in that domain, can you explain more please :) – senior Nov 25 '16 at 13:59
  • Define "doesn't work". In order to do that, you'll almost certainly need to hook your device up to your computer and debug with Chrome (`chrome://inspect`). Make sure to enable USB debugging on your device. Then you should see any errors that get logged to the Javascript console, and you can report them back here. My guess: you're missing or have incorrectly configured the whitelist plugin, OR you've got a missing or incorrect content-security-policy (CSP) meta tag in your index.html. – Kerri Shotts Nov 26 '16 at 18:04

0 Answers0