0

Hello i am new in phonegap. i am create a one html file with login validation. my validation code in php file. and i am run on android emulator. that time this php file is not working on emulator so what can i do?

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>
        </title>

        <link rel="stylesheet" href="jquery.mobile-1.1.1.min.css" />

        <link rel="stylesheet" href="my.css" />
        <style>
            /* App custom styles */
        </style>
        <script src="jquery.min.js"> </script>
        <script src="jquery.mobile-1.1.1.min.js"> </script>
        <script src="my.js">
        </script>
    </head>
    <body>
        <!-- Home -->
        <div data-role="page" id="page1">
            <div data-role="content" style="padding: 15px">
                <div data-role="fieldcontain">
                <div id="message" style="display: none;"></div>
                    <fieldset data-role="controlgroup">
                        <label for="textinput1">
                            Email:
                        </label>
                        <input name="" id="textinput1" placeholder="" value="" type="text" />
                    </fieldset>
                </div>

<script type="text/javascript">
$(document).ready(function(){
    $('#btnValidate').click(function() {

        $('#message').hide(500);

        $.ajax({
            type : 'POST',
            url : 'http://localhost/JQuery/php',
            dataType : 'json',
            data: {
                email : $('#textinput1').val()
            },
            success : function(data){
                $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
                    .text(data.msg).show(500);
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {

                $('#message').removeClass().addClass('error')
                    .text('There was an error.').show(500);
            }
        });

        return false;
    });
});
</script>

<a data-role="button" data-inline="true"  id="btnValidate" data-transition="fade" href="#page1">Submit</a>
            </div>
        </div>
        <script>
            //App custom javascript
        </script>
    </body>
</html>

This is my html code. where i was incorrect so please tall me.

1
  • Is the php code supposed to run on the phone or on a server? Aug 17, 2012 at 12:52

3 Answers 3

2

When you run an a PhoneGap application in the Android emulator, localhost and 127.0.0.1 refer to the Android emulator loopback interface. You can access the development machine using the IP address 10.0.2.2

$.ajax({
    type : 'POST',
    url : 'http://10.0.2.2/JQuery/php',
    dataType : 'json',
    data: {
        email : $('#textinput1').val()
    }...
2
  • when i was run html that time call the error : function(XMLHttpRequest, textStatus, errorThrown) { $('#message').removeClass().addClass('error') .text('There was an error.').show(500); } On MY HTML file
    – XEME
    Aug 17, 2012 at 13:15
  • Do you have a firewall running blocking port 80 on your machine? If that's the case, you must open that port in your firewall.
    – user1597529
    Aug 17, 2012 at 13:48
1

You will need to access your php file by using IP address of your system (something like 192.168.1.2) or setup a virtualhost. Android emulator is loaded as a separate virtual machine so you cannot access localhost for your php files.

1
  • how to set android emulator ip address?
    – XEME
    Aug 17, 2012 at 13:18
0

Assing IP to your system and use That IP addrerss http:// 183.82.166.97:9696/index.php

I configured like this in httpd.conf

Listen 9696 DocumentRoot "D:/PHPworkspace/HWsite" DirectoryIndex index.php AllowOverride All Allow from All
AllowOverride All Allow from All

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.