用jQuery.ajax更新mysql,然后找到页面

时间:2012-05-14 09:34:43

标签: javascript mysql jquery-mobile window.location

我正在使用phonegap和jQuery mobile构建应用程序。在我的应用程序中,我有一个更新mysql的按钮,成功后定位到不同的页面。当我按下按钮mysql得到更新,但浏览器没有找到不同的页面,所以我猜功能不成功?这是我使用的代码,它有一些问题或为什么window.locate即使更新部分也不起作用?

html:

<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<div id="detailsPage" data-role="page" data-add-back-btn="true">
    <div data-role="header">
        <h1>Header</h1>
    </div>
  <div data-role="content"> 
      <input type="button" id="button_id" value="UPDATE" data-theme="b" onClick="UpdateRecord();">
      <input type="button" id="button_id" value="DELETE="d" onClick="DeleteRecord();">
</div>
</body>
</html>

js:

<script>  

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function UpdateRecord(update_id) {
        var id = getUrlVars()["id"]; 
        jQuery.ajax({
            type: "POST", 
            url: serviceURL + "update.php", 
            data: 'id='+id , 
            cache: false, 
            success: function(response) 
            {
                window.location = "list.html"
            }
        });
}

function DeleteRecord(update_id) {
        var id = getUrlVars()["id"]; 
        jQuery.ajax({
            type: "POST", 
            url: serviceURL + "delete.php", 
            data: 'id='+id , 
            cache: false, 
            success: function(response) 
            {
                window.location = "list.html"
            }
        });
    }
</script>

和update.php:

<?php
include 'config.php';
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
// new data
$id = @$_POST['id'];
// query
$sql = "UPDATE table
        SET number=3
        WHERE IND=?";
$q = $conn->prepare($sql);
$q->execute(array($id));
?>

0 个答案:

没有答案
相关问题