我正在创建一个phonegap移动应用程序(android)。我已经使用我的手机模拟了应用程序。当我在本地机器上的表单上进行注册时,它成功并且数据被提交到数据库。但是当我尝试做的时候同样使用我的手机没有任何反应。我认为手机无法到达我机器的回路地址。我怎么能这样做?
注册文件(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.";
?>
答案 0 :(得分:3)
如果您使用本地网络,请使用本地网络IP地址。并确保防火墙已关闭。