Reputation: 43
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.
Upvotes: 0
Views: 1965
Reputation: 1
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
Upvotes: 0
Reputation:
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()
}...
Upvotes: 2
Reputation: 3370
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.
Upvotes: 1