Read local file from QWebView using Ajax request
Tag : cpp , By : Fenix Drakken
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I finally found how to do it. I overrode QNetworkAccessManager. MyQNetworkAccessManager .h: class MyQNetworkAccessManager : public QNetworkAccessManager
{
Q_OBJECT
protected:
virtual QNetworkReply * createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0);
};
QNetworkReply * MyQNetworkAccessManager::createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData) {
QUrl url = req.url();
QString path = url.path();
if (op == QNetworkAccessManager::GetOperation && path.endsWith("xml")) {
QUrl newUrl;
if(path.endsWith("..")) {
newUrl.setUrl("...");
}
else if(path.endsWith("...")) {
newUrl.setUrl("...");
}
else {
newUrl = url;
}
return QNetworkAccessManager::createRequest(QNetworkAccessManager::GetOperation, QNetworkRequest(newUrl));
}
else
{
return QNetworkAccessManager::createRequest(op, req, outgoingData);
}
}
// ....
QWebView *qWebView = new QWebView();
QWebPage *page = qWebView->page();
MyQNetworkAccessManager *networkManager = new MyQNetworkAccessManager();
page->setNetworkAccessManager(networkManager);
qWebView->setPage(page);
qWebView->load(QUrl("..."));
// ....
|
Unable to use AJAX to read a local text file?
Date : March 29 2020, 07:55 AM
wish helps you The content of the file must be loaded using a HTTP call as the xmlhttp.send() method makes a call to the server. Check that the xmlhttp.open("GET","\test.txt",true); method signature expect the second parameter as an URL to the server and the first argument specify the HTTP method (GET/POST) What is the location of the text file from this page you are running, your code will try to load it from the same dir.
|
cannot read local xml file with jquery $.ajax
Tag : jquery , By : user122937
Date : March 29 2020, 07:55 AM
With these it helps with the following changes I got it done: firstly: replace the data.xml to a subdirectory (I don't know if it was this or not)
|
How read json local file with jquery with ajax?
Date : March 29 2020, 07:55 AM
|
Ajax not working when i read a local file
Date : March 29 2020, 07:55 AM
|