[尝试通过jQuery Ajax post方法更新SQL Server中的删除标志。我不确定问题出在我的PHP还是jQuery代码。当我按下Delete按钮时,什么也没发生,但是Web开发工具没有指出语法有什么问题。
这里是HTML:
<div class='dialog' id='editForm' title='Edit' >
<form method='POST' id ='editFo' name = 'editFo' action='post' enctype='multipart/form-data'>
</form>
</div>`
这里是按钮的html:
<button id="deleteFormbtn" >Delete</button>
这是jQuery代码:
$("#deleteFormbtn").click(function(){
$.post ( "deleteRow.php", $("#editForm: input").serializeArray(), function(data){
alert(data);
});
});`
这里是PHP代码:
`
require_once ('sql/connectionstring/connectionstring.php');
$conn = SQLServerConnection();
if(isset($_POST['vendor'])){
$loc_sql = "SELECT TOP 1 loc_id FROM <table> WHERE loc_name = ?";
$parms = array($_GET['loc']);
$loc = sqlsrv_query($conn, $loc_sql, $parms) or die (print_r ( sqlsrv_errors(), true));
while ($q = sqlsrv_fetch_array($loc)){
$loc_id = $q["loc_id"];
}
$username = $_POST['username'];
$password = $_POST['password'];
$comments = $_POST['comments'];
$vendor_website = $_POST['website'];
$vendor = $_POST['vendor'];
$query = "UPDATE <table> SET <column> = '0' WHERE <column> = ?";
$parms = $username;
$result = sqlsrv_query($conn, $query, $parms) or die (print_r ( sqlsrv_errors(), true));
sqlsrv_close($conn);
}
header('Location: <location>);
?>`
$_POST['vendor']
时可以识别它”>if(isset($_POST...) { .... }
”的情况,以便返回错误。关注PHP部分,以JSON格式发送回复。类似于:
$ data = / **无论您要序列化的** /;
header('Content-Type:application / json');
echo json_encode($ data);
您需要在按钮上添加type="button"
,否则页面将重新加载并且请求将不会发送,因为它默认为“提交”。