The following JS function should be sending out a GET request to
with
?query=toast
function sendRequest(str){
var request = new XMLHttpRequest();
console.log('sending request');
request.onreadystatechange = function() {
if (request.readyState == XMLHttpRequest.DONE) {
json=request.responseText;
//json.forEach(function(obj) {
//});
for (word in json){
var row=table.insertRow();
var scoreC=row.insertCell();
var wordC=row.insertCell();
scoreC.innerHTML=json[word];
wordC.innerHTML=word;
}
} else {
concole.log("Silence on the line");
}
}
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
request.open('GET', 'http://127.0.0.1:5000/api.xml?query='+str, true);
request.send();
// and give it some content
//var newContent = document.createTextNode(resp);
//console.log(resp.responseType);
}
Instead, it always queries
ignoring the fact that I required a GET on
1)As Stephan Schrijver lined out
is only valid when it follows
as part of a POST request
It is no longer required for GET requests
2) Also,
must be defined before the readyStateChange function
Try this out
At first, you should create desired URL, open request and then set request header. Let me show an example:
Or in your case: