Phonegap - using eclipse readystate 0 responseetext status 0 statustext error

I am trying to access mysql database data in phonegap app using ajax request. It works fine in php, but when I try to run it over the phone, it gives me an annoying error - Don't forget to find the code:

                   <script>
                        $(document).ready(function () {
                            $("#btnclick").click(function () {              
                                    $.ajax({
                                        url: "http://192.168.1.16:8080/api.php",                                                                                    
                                        datatype: "json",
                                        ContentType:"application/json", 
                                        success: function(respose) 
                                        {                   
                                            alert("It works !!");
                                            alert(JSON.stringify(respose));
                                        },
                                        error: function(err) 
                                        {
                                            alert("It failed ");
                                            alert(JSON.stringify(err));
                                        }                           
                                    });                                             
                                });
                            });
                    </script>
                </head>
                <body>
                    <p>This is a paragraph content</p>

                <h1>Call API from Php</h1>
                <input type="button" value="login" id="btnclick" />
                </body>

      

this is my php api: api.php

            <?php
            header('Access-Control-Allow-Origin: *');

            $servername = "localhost";
            $username = "root";
            $password = "";
            $dbname = "ajax01";

            // Create connection
            $conn = new mysqli($servername, $username, $password, $dbname);

            // Check connection
            if ($conn->connect_error) {
                die("Connection failed: " . $conn->connect_error);
            } 

            else
            {

                    //if(isset($_GET['Username']))
                    {
                        //$username = $_GET['Username'];
                        //$password = $_GET['Password'];

                        $mysql_user = "root";
                        $mysql_password = "";
                        $database = "ajax01";


                        $link = mysqli_connect("localhost","$mysql_user","$mysql_password","$database") or die("Error " . mysqli_error($link));

                        $query = "SELECT * FROM logintable" or die("Error in the connection" . mysqli_error($link)); 


                        //execute the query. 

                        //$query = "update logintable set id='5' where id='1' " or die("Error in the connection" . mysqli_error($link)); 


                        $result = mysqli_query($link, $query); 

                        $totalRows = mysqli_num_rows($result);

                        while($row = mysqli_fetch_array($result)) 
                        { 
                          echo $row["id"] . $row["name"] . $row["password"] ;             
                        }   


                    }
            }
            ?>              

      

and an error in the telephone table: readystate 0 responseetext status 0 error statustext

although the same code works fine on a webserver. Help!

+3


source to share


2 answers


This might help you

sudo cordova plugin add https://github.com/apache/cordova-plugin-whitelist

Now that you have this plugin add this line to your config.xml



<allow-navigation href="http://192.168.1.16:8080/*" />

      

Recover and try again!

0


source


Everything was fine, only the ANDroid manifest.xml needs to be changed: kindly check this one:

Open AndroidManifest.xml file for editing. Add the following node as a child to your node manifest



                <supports-screens
                android:anyDensity="true"
                android:largeScreens="true"
                android:normalScreens="true"
            android:resizeable="true"
            android:smallScreens="true" />

            <uses-permission android:name="android.permission.CAMERA" />
            <uses-permission android:name="android.permission.VIBRATE" />
            <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
            <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
            <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
            <uses-permission android:name="android.permission.READ_PHONE_STATE" />
            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="android.permission.RECEIVE_SMS" />
            <uses-permission android:name="android.permission.RECORD_AUDIO" />
            <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
            <uses-permission android:name="android.permission.READ_CONTACTS" />
            <uses-permission android:name="android.permission.WRITE_CONTACTS" />
            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
            <uses-permission android:name="android.permission.GET_ACCOUNTS" />
            <uses-permission android:name="android.permission.BROADCAST_STICKY" />
            Add a attribute to <activity> node, which is the child node to <application> node android:configChanges="orientation|keyboardHidden"
            Add the following <activity> node as a sibling to existing <activity> node
            <activity android:name="org.apache.cordova.DroidGap" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
                <intent-filter></intent-filter>
            </activity>

      

0


source







All Articles