我正在尝试在我的复选框发生更改时更新我的数据库。我调用的php文件处理了所有的东西,运行得很好。以下是这方面的代码:
<?php
$productid = $_GET['pID'];
$dropshippingname = $_GET['drop-shipping'];
$dbh = mysql_connect ("sql.website.com", "osc", "oscpassword") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("oscommerce");
$dropshippingid = $_GET['drop-shipping'];
$sqladd = "UPDATE products SET drop_ship_id=" . $dropshippingid . "
WHERE products_id='" . $productid . "'";
$runquery = mysql_query( $sqladd, $dbh );
if(!$runquery) {
echo "Error";
} else {
echo "Success";
}
?>
我所要做的就是在url中定义两个变量,我的id条目将在products表ex: www.website.com/dropship_process.php?pID=755&drop-shipping=16下面更新。
下面是调用dropship process.php的jquery函数:
$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}
$('#drop_shipping').change(function() {
var pid = $.urlParam('pID');
var dropshippingid = $(this).val();
$.ajax({
type: "POST",
url: "dropship_process.php",
data: '{' +
"'pID':" + pid + ','
"'drop-shipping':" dropshippingid + ',' +
'}',
success: function() {
alert("success");
});
}
});
});
我想我把我的数据定义错了。这是我第一次使用除了序列化之外的其他任何东西,所以任何指针都会被感激!
发布于 2013-08-28 05:37:50
这样定义你的URl不就足够了吗: url:"dropship_process.php?pID="+ pid +&drop=“+ dropshippingid”
发布于 2013-08-28 05:34:49
ajax代码不正确。用以下代码替换ajax代码:
$.ajax({
type: "POST",
url: "dropship_process.php",
dataType: 'text',
data: {"pID": pid,'drop-shipping': dropshippingid},
success: function(returnData) {
alert("success");
}
});
https://stackoverflow.com/questions/18480023
复制相似问题