Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
Javascript modify response text of XHR request on specified url

So I'm trying to modify the response text of a XHR request but only on a certain url. Heres what I have:

(function(http){
  var get = Object.getOwnPropertyDescriptor(
    http.prototype,
    'responseText'
  ).get;

  Object.defineProperty(
    http.prototype,
    "responseText",
    {
      get: function(){ return get.apply( this, arguments ) + '{"Admin":true}'}
    }
  );
})(self.XMLHttpRequest);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can add parameters to XMLHttpRequest object:

var myUrl = 'https://www.google.es'
var xml = new XMLHttpRequest();
xml.onreadystatechange = function() {
    if ( xml.readyState == 4) {
        console.log(xml.url);
      if(xml.url === 'https://www.google.es'){
        //change response here
      }
    }
};
xml.open("GET", myUrl, true);
xml.url = myUrl;
xml.send();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!