感谢您的答复.因此,我浏览了一些在Google上找到的SO答案和一些教程,这就是我的JS代码所发生的事情. function funcEdit(row_id){ var currentbal = document.getElementById('currentbal' + row_id).value;var dealID = row_id;//organize the data properlyvar data = 'currentbal=' + currentbal.val() + '&dealID=' + dealID.val(); //start the ajax $.ajax({ url: "firstbillsubmitbal.php", type: "GET", data: data, cache: false, success: function() { $('#message').html("<h2>Current balance has been updated!</h2>") } }); }这就是我的firstbillsubmitbal.php页面上发生的事情$dealID = $_GET['dealID'] $currentbal = $_GET['currentbal']$sql = mysql_query("UPDATE deals SET currentbal = '$currentbal', currentbalDone = 'Yes' WHERE deals.dealID = '$dealID' LIMIT 1") or die (mysql_error());但是当我单击按钮调用函数时,什么也没有发生.我想念什么?此外,这就是我调用函数的方式. #COL1#是我的行ID值.<a href="javascript: funcEdit(#COL1#);" class="btn btn-success">Update</a>解决方案使用row_id数据正确调用了您的函数吗? 如果是这样,那可能会给你一个窍门,function funcEdit(row_id){ var currentbal = document.getElementById('currentbal' + row_id).value;var dealID = row_id; //start the ajax $.ajax({ url: "firstbillsubmitbal.php", type: "GET", //pass data like this data: {currentbal:currentbal.val(),dealID: dealID.val()}, cache: false, success: function(data) { if (data=="1") $('#message').html("<h2>Current balance has been updated!</h2>") } }); }并在php文件中$dealID = $_GET['dealID'] $currentbal = $_GET['currentbal']$sql = mysql_query("UPDATE deals SET currentbal = '$currentbal', currentbalDone = 'Yes' WHERE deals.dealID = '$dealID' LIMIT 1") or die (mysql_error());echo "1" ; // if update successfulelse echo "0" // if update unsuccessfulI have a simple form before:<form method="post" action="firstbillsubmitbal.php?id=#COL1#"> <input name="currentbal" type="text" id="currentbal" class="input-mini" /> <input type="submit" id="submit" value="Save" class="btn btn-success" /></form>Which calls this page for processing firstbillsubmitbal.php$dealID = $_GET["id"]; $currentbal = mysql_real_escape_string(stripslashes($_POST['currentbal']));$sql = mysql_query("UPDATE deals SET currentbal = '$currentbal', currentbalDone = 'Yes' WHERE deals.dealID = '$dealID'") or die (mysql_error());It was working fine for single transactions. But I need to edit it a bit since I am displaying my data in a table now. I now have this js code when I click on a btn on my table per row, passes my row_id and currentbal calue, I got it working but I would like to know from this js code how do I process my form?function funcEdit(row_id){ var currentbal = document.getElementById('currentbal' + row_id).value; var r=confirm("Are You Sure You Want To Proceed?"); if(r==true) { alert("Record is saved"); } else { alert("Cancelling Transaction"); } }The js code has two variables only at the moment which is row_id = this is basically the ID of the db row andcurrentbal = which is the value I want to upload to my dbMy question basically is how do I call my firstbillsubmitbal.php file and what/how do I edit on my php file so that my row_id and currentbal are uploaded on my db since I am no long using POST.Thank you for the replies. So I went thru some SO answers and some tutorials I found on google and this is what happened to my js code. function funcEdit(row_id){ var currentbal = document.getElementById('currentbal' + row_id).value;var dealID = row_id;//organize the data properlyvar data = 'currentbal=' + currentbal.val() + '&dealID=' + dealID.val(); //start the ajax $.ajax({ url: "firstbillsubmitbal.php", type: "GET", data: data, cache: false, success: function() { $('#message').html("<h2>Current balance has been updated!</h2>") } }); }And this is what happened to my firstbillsubmitbal.php page$dealID = $_GET['dealID'] $currentbal = $_GET['currentbal']$sql = mysql_query("UPDATE deals SET currentbal = '$currentbal', currentbalDone = 'Yes' WHERE deals.dealID = '$dealID' LIMIT 1") or die (mysql_error());But nothing happens when I click on the button to call my function. What am I missing?Also, here is how I call my function. #COL1# is my row ID value.<a href="javascript: funcEdit(#COL1#);" class="btn btn-success">Update</a> 解决方案 Are your function getting called correctly with row_id data ? if so then might be this will give you a trick,function funcEdit(row_id){ var currentbal = document.getElementById('currentbal' + row_id).value;var dealID = row_id; //start the ajax $.ajax({ url: "firstbillsubmitbal.php", type: "GET", //pass data like this data: {currentbal:currentbal.val(),dealID: dealID.val()}, cache: false, success: function(data) { if (data=="1") $('#message').html("<h2>Current balance has been updated!</h2>") } }); }and in php file $dealID = $_GET['dealID'] $currentbal = $_GET['currentbal']$sql = mysql_query("UPDATE deals SET currentbal = '$currentbal', currentbalDone = 'Yes' WHERE deals.dealID = '$dealID' LIMIT 1") or die (mysql_error());echo "1" ; // if update successfulelse echo "0" // if update unsuccessful 这篇关于使用javascript更新sql记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-17 20:20