我有一个HTML文件,在我的Qt MainWindow中作为WebView加载,该文件位于localhost XAMPP文件夹中。该文件基本上从用户获取两个日期和时间间隔,当用户单击“获取查询”按钮时,地图将显示从XAMPP上的MySQL数据库中获取的查询总量作为热图。但是,尝试从Qt运行此HTML文件 - 单击HTML窗口的获取查询按钮 - 给我Ajax POST错误,我无法从Qt访问数据库,而localhost副本可以。我还尝试POST到使用NetworkAccessManager获取查询的PHP文件,但我得到了一个“未知错误”作为回复。有没有一种特殊的方法来解决这个问题? HTML-jQuery代码和NetworkAccessManager邮政编码如下:
HTML-jQuery Part:
<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">
<select name = "freq">
<option value = "all" selected = "true">all</option>
<option value = "hourly">hourly</option>
<option value = "daily">daily</option>
<option value = "weekly">weekly</option>
<option value = "monthly">monthly</option>
</select>
data between
<input type="text" id="time" style="border:0; color:#f6931f; font-weight:bold;" />
<input type="submit" name="fetch" value="Fetch">
</form>
我使用的NetworkAccessManager部分用于测试我的PHP文件以获得回复:
QNetworkAccessManager* mNetworkManager = new QNetworkAccessManager(this);
QObject::connect(mNetworkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onNetworkReply(QNetworkReply*)));
connect(mNetworkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
QUrl url = "http://localhost/heatQuery.php";
QUrl params;
params.addQueryItem("date1","2011-07-13");
params.addQueryItem("time1","00:00");
params.addQueryItem("date2","2011-07-13");
params.addQueryItem("time2","13:00");
params.addQueryItem("freq","hourly");
QByteArray data;
data.append(params.toString());
data.remove(0,1);
QNetworkRequest request;
request.setUrl(url);
request.setHeader(QNetworkRequest::ContentTypeHeader,
QVariant("application/x-www-form-urlencoded"));
mNetworkManager->post(request, data);
void MainWindow::replyFinished(QNetworkReply *reply){
//Use the reply as you wish
QString text(reply->errorString());
std::cout<<"REPLY IS" << text.toStdString() << std::endl;
}
答案 0 :(得分:1)
当localhost副本成功访问数据库时,Change the permission of your database and then run
。
要更改数据库权限以完全执行此操作[假设您使用的是linux]命令。
chmod 777 database_name