My attempt to fetch a website using a GET request in JavaScript within QWebView
is causing an error when I use jQuery.ajax
. However, switching to XMLHttpRequest
seems to solve the issue.
Here is the revised JavaScript code:
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var data = jQuery.parseXML(xmlhttp.responseText);
alert(data);
} else if (xmlhttp.readyState == 4) {
alert(JSON.stringify(xmlhttp));
}
}
xmlhttp.open("GET", CO_SERVICE, true);
xmlhttp.setRequestHeader("Authorization", "Basic " + btoa("user:password"));
xmlhttp.send();
The code works perfectly in Chrome. However, when I run my Qt application and load the file using:
QNetworkProxyFactory::setUseSystemConfiguration(true);
ui->webView->load(QUrl("qrc:///index.html"));
ui->webView->show();
I encounter the following error:
Can you help me identify what mistake I might be making?