Skip to content Skip to sidebar Skip to footer

Enable Android App To Connect To The Internet

I have created a simple app using Phohegap to retrieve few records frm a remote database using the following index.html:

Solution 1:

Add these lines

<scripttype="text/javascript"charset="utf-8"src="cordova.js"></script><scripttype="text/javascript"charset="utf-8">

Also you said you want to retrieve, so this should be a GET call , not POST.

Also use <!DOCTYPE html> (proper coding standard)

Edit : Example GET call

$.ajax({
                url: "http://abcd.com",
                headers: {
                    "X-API-KEY": "2b9asdedqedqxdqd7956e6f7a",
                    "Content-Type": "application/json"
                },
                type: "GET",
                data: fromDatan,
                dataType: "JSON",
                success: function(fromData, status, jqXHR) {
                    alert(JSON.stringify(fromData));
                },

                error: function(jqXHR, status) {
                    alert(JSON.stringify(jqXHR));
                }
                });

EDIT : This is a sample code which can POST to a test server

<!DOCTYPE html><html><head><scriptsrc="http://code.jquery.com/jquery-latest.min.js"></script><scriptlanguage="javascript"type="text/javascript">
        <!--
        functiongreeter() {

          var accx = 5;
          var accy = 6;
          var accz = 7;


                var output = [];
                output[0] = {
                        name: "Accel_X",
                        value: accx.toString(), // retrieve x
                    };
                    output[1] = {
                        name: "Accel_Y",
                        value: accy.toString(), // retrieve y
                    };
                    output[2] = {
                        name: "Accel_Z",
                        value: accz.toString() // retrieve z
                    };


                var fromData = {};
                fromData.output = output;

                var fromDatan = JSON.stringify(fromData);
                alert(fromDatan);


                jQuery.ajax({
                    url: "http://posttestserver.com/post.php",
                    type: "POST",

                    data: fromDatan,

                    dataType: "JSON",

                    success: function(fromDatan, status, jqXHR) {
                        alert(JSON.stringify(fromData));
                    },

                    error: function(jqXHR, status) {
                        alert(JSON.stringify(jqXHR));
                    }

                    /*
                    error:function(jqXHR,text_status,strError){
            alert("No Connection");},
        timeout:60000,
        success:function(data){
            $("#result").html("");
                for(var i in data){
                    $("#result").append("<li>"+data[i]+"</li>");
                }
            }*/
                });
                returnfalse;
            }
            //--></script></head><body><buttononclick="greeter();">Click me</button></body></html>

I tried with your url, not working. However will let you know if I can

Post a Comment for "Enable Android App To Connect To The Internet"