我正在开发一个 Qt 程序,其中包含一个作为 HTML 页面的 OpenStreetMap 应用程序,并且该页面能够访问数据库——通过提交一个包含查询开始和结束日期的 ajax 表单——以便检索和可视化查询地图。我想将此查询过程从 HTML/Javascript 部分移至 Qt。到目前为止,我设法通过 Qt 与浏览器进行交互,但我仍然遇到以下问题:
1) 单击 Qt 的 fetch queries 按钮,应该会弹出一个警告框,提示 Ajax POST 失败 - 数据库不在我当前的笔记本电脑上,当我单击 HTML 浏览器窗口的 fetch 时应该会收到错误查询按钮或 Qt 的获取按钮 -
2)而且,每当我单击 HTML 浏览器的 Fetch 查询按钮时,它会显示 POST 警告,但也会显示额外的 POST 警告警报框,具体取决于我单击 Qt 的 Fetch 查询按钮的次数。- 例如,如果我连续 5 次单击 Qt 的 fetch 查询按钮,然后单击 HTML 窗口的 fetch 按钮一次,我会连续收到 6 条 POST 失败消息 -
HTML 代码如下所示:
<form id="ajaxForm" action="index.php" method="post">
Start <input type="text" name = "date1" id = "datepicker" value = "2011-07-13" style = "width:70px">
<input type="text" name = "time1" id = "timepicker1" value = "00:00" style = "width:40px">
End <input type="text" name = "date2" id = "datepicker2" value = "2011-07-13" style = "width:70px">
<input type="text" name = "time2" id = "timepicker2" value = "00:01" style = "width:40px">
AJAX形式的post方法是这样的:
<script type="text/javascript">
$(document).ready(function(){
// ajaxForm submit
$('#ajaxForm').submit(function() {
$.ajax({
type: 'POST',
url: 'heatQuery.php',
data: $(this).serialize(),
dataType: 'json',
success: function(response)
{
// update the points for heatmap layer
updateHeatMap(response);
},
error: function(errorMsg)
{
alert('Error in Ajax POST');
}
});
return false;
});
});
</script>
最后,调用该函数的 Qt 代码是这样的:
void MainWindow::onButtonClicked() // clicking the button in order to POST
{
//the QString a is the same ajax post function as declared above
QString a = "$(document).ready(function(){$('#ajaxForm').submit(function() {$.ajax({type: 'POST',url: 'heatQuery.php',data: $(this).serialize(),dataType: 'json',success: function(response){updateHeatMap(response);},error: function(errorMsg){alert('Error in Ajax POST');}});return false;});});";
this->view->page()->mainFrame()->evaluateJavaScript(a);
}
关于这里有什么问题的任何想法?谢谢。