Trying to utilize the Get method to send an Ajax request, I have encountered an issue. Despite adding an alert to my request function to confirm the link, no alert is displayed!
Here is my code:
Below is my html.twig view:
<a href="#" onclick="request( {{ path('mooniki_vote_acteur', { 'id' : 8 } ) }} );">Click here</a>
Here is my javascript code:
function request(path) {
alert(path);
var xhr = getXMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
alert(xhr.responseText); // Retrieved text data
}
};
xhr.open("GET", path, true);
xhr.send(null);
}
Interestingly, when I provide a string argument in the request function, the alert is displayed successfully.
Thank you.