将 phone 应用程序(phone 差距)连接到本地主机文件(在本地计算机中)
Connecting a phone app (phonegap) to a localhost file(in local machine)
我正在创建一个 phonegap 移动应用程序 (android)。我已经使用我的 phone.When 模拟了该应用程序 我在本地机器上的表格上注册成功了当我尝试使用我的 phone 做同样的事情时,数据被提交给 database.But 什么都没有 happens.The 我认为是 phone 无法到达我的环回地址machine.How我可以解决这个问题吗?
注册文件(HTML)
<script type="text/javascript">
$(document).ready(function(){
$("#signup").click(function(){
var name = $("#name").val();
var email = $("#email").val();
var username=$("#username").val();
var password=$("#password").val();
// Returns successful data submission message when the entered information is stored in database.
var dataString = 'name='+ name + '&email='+ email + '&username=' + username + '&password=' + password;
if(name==''|| email=='' || username=='' || password=='')
{
alert("Please Fill All Fields");
}
else
{
//AJAX code to submit form.
$.ajax({
type: "POST",
url: "http://127.0.0.1/test/signup.php",
data: dataString,
cache: false,
success: function(result){
alert(result);
}
});
}
return false;
});
});
</script>
<div class="app">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Sign Up</h3>
</div>
<div class="panel-body">
<div class="form-group">
<input type="text" name="name" id="name" class="form-control" placeholder="Full Name" required>
<br>
<input type="email" name="email" id="email" class="form-control" placeholder="Email Address" required>
<br>
<input type="text" name="username" id="username" class="form-control" placeholder="Username" required>
<br>
<input type="password" name="password" id="password" class="form-control" placeholder="Password" required>
<br>
<input type="submit" id="signup" value="Submit" class="btn btn-success">
</div>
</div>
<b>or Sign In <a href="#" class="btn btn-primary" data-toggle="modal" data-target="#login-mod">Here</a></b>
</div>
</div>
注册文件(PHP 文件)
<?php
header('Access-Control-Allow-Origin: *');
$con=mysqli_connect("localhost","root","","test") or die("error in server");
$name=$_POST['name'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];
$sql="INSERT INTO signup(name,email,username,password) values('$name','$email','$username',sha1('$password')) ";
$qry=mysqli_query($con,$sql) or die(mysqli_error($con));
if($qry){echo "Registration was successful.";}
else echo "A network error occured.Please retry.";
?>
如果您使用的是本地网络,请使用本地网络 IP 地址。并确保您的防火墙是 OFF
.
我正在创建一个 phonegap 移动应用程序 (android)。我已经使用我的 phone.When 模拟了该应用程序 我在本地机器上的表格上注册成功了当我尝试使用我的 phone 做同样的事情时,数据被提交给 database.But 什么都没有 happens.The 我认为是 phone 无法到达我的环回地址machine.How我可以解决这个问题吗?
注册文件(HTML)
<script type="text/javascript">
$(document).ready(function(){
$("#signup").click(function(){
var name = $("#name").val();
var email = $("#email").val();
var username=$("#username").val();
var password=$("#password").val();
// Returns successful data submission message when the entered information is stored in database.
var dataString = 'name='+ name + '&email='+ email + '&username=' + username + '&password=' + password;
if(name==''|| email=='' || username=='' || password=='')
{
alert("Please Fill All Fields");
}
else
{
//AJAX code to submit form.
$.ajax({
type: "POST",
url: "http://127.0.0.1/test/signup.php",
data: dataString,
cache: false,
success: function(result){
alert(result);
}
});
}
return false;
});
});
</script>
<div class="app">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Sign Up</h3>
</div>
<div class="panel-body">
<div class="form-group">
<input type="text" name="name" id="name" class="form-control" placeholder="Full Name" required>
<br>
<input type="email" name="email" id="email" class="form-control" placeholder="Email Address" required>
<br>
<input type="text" name="username" id="username" class="form-control" placeholder="Username" required>
<br>
<input type="password" name="password" id="password" class="form-control" placeholder="Password" required>
<br>
<input type="submit" id="signup" value="Submit" class="btn btn-success">
</div>
</div>
<b>or Sign In <a href="#" class="btn btn-primary" data-toggle="modal" data-target="#login-mod">Here</a></b>
</div>
</div>
注册文件(PHP 文件)
<?php
header('Access-Control-Allow-Origin: *');
$con=mysqli_connect("localhost","root","","test") or die("error in server");
$name=$_POST['name'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];
$sql="INSERT INTO signup(name,email,username,password) values('$name','$email','$username',sha1('$password')) ";
$qry=mysqli_query($con,$sql) or die(mysqli_error($con));
if($qry){echo "Registration was successful.";}
else echo "A network error occured.Please retry.";
?>
如果您使用的是本地网络,请使用本地网络 IP 地址。并确保您的防火墙是 OFF
.