The functionality of XMLHttpRequest becomes unreliable when dealing with GET parameters

I'm attempting to retrieve the DOM of a specific page.

var req = new XMLHttpRequest();
req.open( 'GET', '/sport-hobby-kultura?adListing-visualPaginator-page=2&adListing-url=sport-hobby-kultura&do=adListing-visualPaginator-showPage', true );
// set responseType document to return DOM
req.responseType = 'document' || '';
// set X-Requested-With header to check that is ajax request
req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
req.send();

However, I am encountering an issue where it returns NULL. It seems to be related to the parameters in the URL of the request. Surprisingly, when I remove them, the request functions flawlessly (example below):

var req = new XMLHttpRequest();
req.open( 'GET', '/sport-hobby-kultura', true );
// set responseType document to return DOM
req.responseType = 'document' || '';
// set X-Requested-With header to check that is ajax request
req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
req.send();

Any insights on why it only works without the GET parameters? The page behaves correctly when accessed via browser or API tester.

Answer №1

When setting <code>req.responseType = 'document' || '';
, the value will always be "document"

If the responseType is not actually set to "document", a null response will be returned.

To see what is returned, try removing the responseType or replacing it with the correct type.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Experiencing issues with integrating Vue.js into Spring MVC JSP pages

I am currently in the process of integrating views into my JSP files for my Spring MVC application. I have set up a very basic configuration, but I am encountering an issue where the message displayed from the 'msg' attribute in the data object a ...

I am looking for JavaScript or jQuery code that allows me to incorporate a "Save This Page As" button

Is there a way to enhance the saving process for users visiting an HTML page, rather than requiring them to go through File > Save As? I am interested in implementing a "Save Page As" button on the page that would trigger the save as dialog when clicke ...

Adaptive Container with Images that are not stretched to full width

Is there a way to achieve the same effect as seen in images 2 and 3 here: Although these images already have their own "padding," I'm curious if it can be replicated using just jQuery and CSS? I would appreciate any help or insights on this. Thank y ...

Display an image in a DIV by loading it from a URL provided in a TEXT BOX

I am having trouble loading an image into a div tag from a URL that is obtained from a text box. Here is my current code snippet, but I can't figure out what else needs to be done: <html lang="en"> <head> </head> <bod ...

Vue.js blocks the use of iframes

I've come across a peculiar issue where I need to embed an iframe inside a Vue template and then be able to modify that iframe later. The code snippet below shows the simplified version of the problem: <html> <body> <div id="app" ...

What could be causing Loudev jQuery multiselect to generate duplicates?

The concept involves allowing users to select a main bank branch via a search textbox that triggers a jQuery AJAX request. If the user wishes to add more branches, they can use a multiselect functionality provided later in the form for selecting one or mul ...

What is the best way to retrieve the input value from post.ejs?

app.js var express = require('express'); var bodyParser = require('body-parser'); var app = express(); var passport = require('passport'); var localStrategy = require('passport-local'); var axios = require("axi ...

The conversion of a newline in an Angular page is done using &lt;br/&gt tag

Here is a function I have: setLocalVariableOnAccepted(ogp, hb, responseJson) { if (responseJson.ofgp === undefined) { this.ogpStatus = 'orange'; this.ogpStatusMsg = responseJson.ofgp + ', <br/> No change. Previous va ...

The workings of the toString() function within Objects

Recently while delving into a book on Js, I stumbled upon the intriguing topic of Object to primitive conversion. The author made an interesting point in the book: For historical reasons, if toString or valueOf returns an object, there’s no error, but ...

Upgrade the JavaScript source code from the backbean JSF

In my XHTML file, I have included Javascript like this: <script src="test1.js"></script> Additionally, I have a few other Javascript files which are actually themes. I want to provide users with the option to change the theme (Javascript nam ...

Transforming text colors dynamically using Vue.js

Here is an Angular code snippet: <div [style.color]="'#' + prod.id.substring(0,6)"> <small>{{ prod.id }}</small> </div> Now I want to create a similar code using vue.js. ...

Learn how to show image information in a separate div by clicking on the image using jQuery

Is there a way to show or hide information of an image in a separate div by clicking on the image itself? $(document).ready(function () { $(".cell").click(function () { $(this).find("span").toggle("slow"); }) }); <div class="cell"> ...

Retrieve JSON key values dynamically with jQuery

My JSON data is dynamic, and I need to access the 'bf' key within it. The keys 'xxxxxx20160929' and 'yyy813AI20160929' can change but the structure of the JSON remains consistent. { "resultData": [ { "a": "124", ...

Why does Vue only change a specific array element without updating the DOM?

My curiosity is piqued by a puzzling issue with updating specific items in an array using Vue.js. The documentation cautions that: Due to limitations in JavaScript, Vue cannot detect the following changes to an array: When you directly set an item with th ...

The THREE.js FBXLoader mistakenly identifies .png files as .psd files, causing issues with loading materials

While using the THREE.js FBXLoader to import a .fbx file, I noticed that the model is only partially loaded, and the alpha textured parts are not loading at all. An error message I encountered is: FBXLoader: PSD textures are not supported, creating emp ...

Gradually returning to the top with Vuetify's smooth scroll feature

Looking for a way to make the scrolling back to the top of the page smoother on my website. The button I currently have in place does the job, but it's not as smooth as I would like. Any suggestions on how to improve this? I've checked similar q ...

Vuex bombards with errors without any clear explanation during commit

Within my Plugin, I am faced with the following code snippet: import firebase from 'firebase' export default context => { firebase.auth().onAuthStateChanged(userObject => { // eslint-disable-next-line no-console console.log({ us ...

Layered parallax scenery

I'm interested in creating a parallax effect similar to this example. https://medium.com/@PatrykZabielski/how-to-make-multi-layered-parallax-illustration-with-css-javascript-2b56883c3f27 However, I find the use of HAML and Coffeescript in the mentio ...

Arranging array elements according to the values in another array

I am working with an array of selections: var selections = ( JSON.stringify($('#approval').select2('data')) ); var selections = JSON.parse("[" + selections + "]"); When I use console.log with selections, the output is: https://i. ...

Why is the editor not displaying the correct line number when the enter key is pressed repeatedly in JavaScript?

I am currently working on developing an editor using JavaScript. My goal is to display a line count (e.g., 1, 2, 3) whenever the user presses 'Enter' to change lines. I have successfully managed to count the line changes upon pressing 'Enter ...