在我的 CMS 中,我有一个大表,存储在所有客户公司中。在 Position
表中,我想存储客户端的 id
。
我有 addPosition
页面,必须允许插入这样的 id
选择客户端名称。
我想开发它的方式是弹出一个对话框,从中选择整个客户端列表,然后对话框的结果应该存储在一个隐藏字段中(例如)。
是否可以使用 jQuery 或 ajax?如果是,如何?如果不是,哪个是该问题的良好解决方法(或者可能是更好的解决方案)?
附言PHP 部分应该不是问题。
最佳答案
如果您询问如何在 jQuery 中执行 AJAX 请求,这是一种方法:
HTML:
<div id="message" style="display:none"></div>
<form action="script.php" method="post" id="myForm">
<select name="employees">
<option value="1">Joh Smith</option>
<option value="2">Janeh Doe</option>
</select>
</form>
JQuery:
$('#myForm').on('submit', function() {
var $this = $(this);
$.ajax({
url: $this.attr('action'),
type: $this.attr('method'),
data: $this.serialize(),
dataType: 'json',
success: function(response) {
if(response.success) {
$('#message')
.text('Database updated successfully')
.addClass('success')
.show();
}
else {
$('#message')
.text('Error happened, AJAX request completed but PHP had a problem.')
.addClass('error')
.show();
}
},
error: function() {
alert('Error happened, AJAX request could not be completed.');
}
});
return false;
});
在 PHP 中,如果您的数据库已成功更新:
echo json_encode(array(
'success' => true
));
否则:
echo json_encode(array(
'success' => false
));
关于php - 在 sql 表的所有行之间进行选择的 Jquery/Ajax 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12670275/