我正在開發一個簡單的應用程序,以使用phonegap保存mysql數據庫(xampp)上的記錄。不過,我正在某處被困住。 我的代碼一直寫「連接...」永遠不保存數據庫上的記錄。我研究了所有,但我似乎無法解決問題請能在某處向我顯示我的代碼中的錯誤?謝謝 也許它的網址,我不知道, 注:我的網址是從phonegap服務器。在手機上使用jquery在Xampp上插入數據
index.html
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body>
<script src="jquery-3.1.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
$(document).ready(function()
{
$("#insert").click(function(){
var firstname=$("#firstname").val();
var lastname=$("#lastname").val();
var phone=$("#phone").val();
var dataString="firstname="+firstname+"&lastname="+lastname+"&phone="+phone+"&insert=";
if($.trim(firstname).length>0 & $.trim(lastname).length>0 & $.trim(phone).length>0)
{
$.ajax({
type: "POST",
url: "http://10.250.216.195:3000/insert.php",
data: dataString,
crossDomain: true,
cache: false,
beforeSend: function(){ $("#insert").val('Connecting...');},
success: function(data){
if(data=="success"){
console.log(data);
alert("inserted");
$("insert").val('submit');
}
else if (data=="error"){
console.log(data);
alert("error");
}
}
});
} return false;
});
}
);
</script>
<div data-role ="page" id ="page1">
<div data-role ="header">
<h1>Hello World</h1>
<center><h3>Register</h3>
<input type="hidden" id="id" value=""/>
<label for ="Firstname" class="ui-hidden-accessible"></label> <input type = "text" id="firstname" placeholder ="firstname" required="required"><br>
<label for ="Lastname" class="ui-hidden-accessible"></label> <input type = "text" id="lastname" placeholder ="lastname" required="required"><br>
<label for ="Phone" class="ui-hidden-accessible"></label> <input type = "text" id="phone" placeholder ="Phone" required="required"><br>
<input type="button" value="insert" id = "insert"></center>
</div>
insert.php
<?php
include "dbconfig.php";
if(isset($_POST['insert']))
{
$first=$_POST['firstname'];
$last=$_POST['lastname'];
$phone=$_POST['phone'];
$first = mysqli_real_escape_string($con,$_POST['firstname']);
$last = mysqli_real_escape_string($con,$_POST['lastname']);
$phone = mysqli_real_escape_string($con,$_POST['phone']);
$q=mysqli_query($con,"INSERT INTO phone (firstname,lastname,phone) VALUES ('$first','$last','$phone')");
if($q)
echo "success";
else
echo "error";
}
?>
我認爲沒有人對此有任何意見:( – masquellett