0

我在 Phonegap 项目中遇到问题,我无法从 Phonegap Developer App 更新 MySQL 数据库中的数据。

这是代码

<html>
<head>
 <link rel="stylesheet" type="text/css" href="http://code.ionicframework.com/1.2.4/css/ionic.css">
 <script type="text/javascript" src="js/http://code.jquery.com/jquery-2.2.2.min.js"></script>
 <script type="text/javascript" src="js/geturi.js"></script>
 <script type="text/javascript">
 $(document).ready(function(){
 var id = decodeURI(getUrlVars()["id"]);
 var title = decodeURI(getUrlVars()["title"]);
 var duration = decodeURI(getUrlVars()["duration"]);
 var price = decodeURI(getUrlVars()["price"]);
 $("#id").val(id);
 $("#title").val(title);
 $("#duration").val(duration);
 $("#price").val(price);
 $("#update").click(function(){
 var id=$("#id").val();
 var title=$("#title").val();
 var duration=$("#duration").val();
 var price=$("#price").val();
 var dataString="id="+id+"&title="+title+"&duration="+duration+"&price="+price+"&update=";
 $.ajax({
 type: "POST",
 url:"http://localhost/tes/update.php",
 data: dataString,
 crossDomain: true,
 cache: false,
 beforeSend: function(){ $("#update").val('Connecting...');},
 success: function(data){
 if(data=="ok")
 {
 alert("Updated");
 $("#update").val("Update");
 }
 else if(data=="error")
 {
 alert("error");
 }
 }
 });

 });
 $("#delete").click(function(){
 var id=$("#id").val();
 var dataString="id="+id+"&delete=";
 $.ajax({
 type: "GET",
 //url: "http://phonegappro.esy.es/test/delete.php",
 url:"http://localhost/tes/delete.php",
 data: dataString,
 crossDomain: true,
 cache: false,
 beforeSend: function(){ $("#delete").val('Connecting...');},
 success: function(data){
 if(data=="ok")
 {
 alert("Deleted");
 $("#delete").val("Delete");
 }
 else if(data=="error")
 {
 alert("error");
 }
 }
 });

 });
 });
 </script>
</head>
<body>
 <div class="bar bar-header bar-positive" style="margin-bottom:80px;">
 <a href="index.html" class="button button-clear">Home</a>
 <h1 class="title">Update Database</h1>
 <a class="button button-clear" href="readjson.html">Read JSON</a>
 </div><br/><br/>
 <div class="list">
 <input type="hidden" id="id" value=""/>
 <div class="item">
 <label>Title</label>
 <input type="text" id="title" value=""/>
 </div>
 <div class="item">
 <label>Duration</label>
 <input type="text" id="duration" value=""/>
 </div>
 <div class="item">
 <label>Price</label>
 <input type="text" id="price" value=""/>
 </div>
 <div class="item">
 <input type="button" id="update" class="button button-block" value="Update"/>
 <input type="button" id="delete" class="button button-block" value="Delete"/>
 </div>
 </div>

</body>
</html>

还有我做的网络服务

<?php
 include "db.php";
 if(isset($_POST['update']))
 {
 $course_id=$_POST['course_id'];
 $title=$_POST['title'];
 $duration=$_POST['duration'];
 $price=$_POST['price'];
 $q=mysql_query("UPDATE `course_details` SET `title`='$title',`duration`='$duration',`price`='$price' where `id`='$course_id'");
 if($q)
 echo "ok";
 else
 echo "error";
 }
 ?>

我的问题是:

  1. 我需要先构建应用程序才能使其正常工作吗?
  2. 这个问题真的经常出现吗?
  3. 我使用 Phonegap Desktop 并且我没有更改 config.xml 文件中的任何内容,我是否需要更改某些内容才能使其正常工作?
4

0 回答 0