Ajax request receives no response [duplicate]












2















This question already has an answer here:




  • How to access the correct `this` inside a callback?

    8 answers



  • es6 Javascript class using this inside a callback [duplicate]

    2 answers



  • Why does the setInterval callback execute only once?

    2 answers




today I come for the following problem that I'm presenting with a new approach that I want to apply with the Ajax requests.



I have to explain that I commonly work with JQuery this type of requests, but I'm doing some tests with this new approach to see if I can solve some situations that I have not been able to solve with JQuery.



I'm working with a class that I'm developing and with which I'm just starting with the most basic, which is to make a request for plain text.



This is the basic ajax class that I have developed so far.



class Ajax {

constructor () {

this.xhr = null;
if ( XMLHttpRequest ) {

this.xhr = new XMLHttpRequest ();

} else if ( ActiveXObject ) {

try {

this.xhr = new ActiveXObject ( "MSXML2.XMLHTTP" );

} catch ( e ) {

try {

this.xhr = new ActiveXObject ( "Microsoft.XMLHTTP" );

} catch ( e ) {

// throws error log
}
}
}
if ( !this.xhr ) {

alert ( "The browser does not have support to make this type of requests to the server." );
}
}

send ( method, event, url ) {

var textoAjax = "";
this.xhr.open ( method, url, true );
this.xhr.setRequestHeader ( 'X-Requested-With', 'XMLHttpRequest');
this.xhr.setRequestHeader ( "Content-Type", "text/plain" );
this.xhr.onreadystatechange = this.readyStateChange ();
this.xhr.send ( event );
}

readyStateChange () {

if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == "200" ) ) {

document.getElementById ( "responsePhp" ).innerHTML = this.xhr.responseText;
}
}
}

function sendRequest () {

let ajax = new Ajax ();
ajax.send ( "POST", null, "sys/libs/common/PhpAjaxBridge.php" );
}


This is the test html.





<html>
<head>
<meta charset="UTF-8">
<title>Simple Ajax Request</title>
<script type="text/javascript" src="http://localhost/ecomod/indexes/Ajax.js"></script>
</head>
<body>
<div id="responsePhp"></div>
<button onclick="sendRequest();">Send Simple Ajax Request</button>
</body>
</html>


And this is the test php file.



header ( 'Content-type: text/plain' );
echo "Hi. What did you expect? ;P";


The problem is that when I click on the launcher button of my ajax request, although this arrives in my test php file, the answer to that request never arrives. I know that it is strange that there is no return on this request, given that it is a very simple example, but in fact that is the case.



I have tried to make some additional gadget as it is, to make use of the callback functions, but I still do not get an answer.



Here the implementation of the callback.



class Ajax {

constructor () {

this.xhr = null;
if ( XMLHttpRequest ) {

this.xhr = new XMLHttpRequest ();

} else if ( ActiveXObject ) {

try {

this.xhr = new ActiveXObject ( "MSXML2.XMLHTTP" );

} catch ( e ) {

try {

this.xhr = new ActiveXObject ( "Microsoft.XMLHTTP" );

} catch ( e ) {

// throws error log
}
}
}
if ( !this.xhr ) {

alert ( "The browser does not have support to make this type of requests to the server." );
}
}

send ( method, event, url ) {

var textoAjax = "";
this.xhr.open ( method, url, true );
this.xhr.setRequestHeader ( 'X-Requested-With', 'XMLHttpRequest');
this.xhr.setRequestHeader ( "Content-Type", "text/plain" );
this.xhr.onreadystatechange = this.readyStateChange ( this.readyStateChangeCallback );
this.xhr.send ( event );
}

readyStateChange ( callback ) {

callback ( this.xhr.readyState );
}

readyStateChangeCallback ( state ) {

if ( state == 4 ) {

if ( this.xhr.status == 200 ) {

document.getElementById ( "responsePhp" ).innerHTML = this.xhr.responseText;
}
}
}
}

function sendRequest () {

let ajax = new Ajax ();
ajax.send ( "POST", null, "sys/libs/common/PhpAjaxBridge.php" );
}


As you can see here I show you the response from the server, but it never reaches the client



Response Headers



Response Text



What can be happening? What can I be forgetting or forgetting?



Thanks in advance.



PD: I have reviewed many threads in this forum and many others but none can explain what is happening or at least do not explain what happens to me, I have tried any solution that they have presented but none manages to unveil the mystery that it happens to me. :s
Sorry for the length but I wanted to be very explicit and place the code as is with the errors described



update: if I eliminate the parentheses in the line



this.xhr.onreadystatechange = this.readyStateChange ();


as suggested by Phil, the following error occurs




Uncaught TypeError: Cannot read property 'readyState' of undefined at XMLHttpRequest.readyStateChange (Ajax.js:84)




where the line in question is this



if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == 200 ) ) {


On the other hand I must note that this.xhr.readyState only comes to take the value 1. The values 2, 3 and 4 never get to receive










share|improve this question















marked as duplicate by Phil javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 23:03


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • this.xhr.onreadystatechange = this.readyStateChange (); 👈 you're executing the readyStateChange() method here immediately instead of assigning it as a callback. Even if you remove the (), you're still going to run into problems accessing this.
    – Phil
    Nov 11 at 23:01










  • The TL;DR of the duplicate posts is that you want this.xhr.onreadystatechange = () => { this.readyStateChange() }. You might also be interested in the onload event as well as the more modern Fetch API
    – Phil
    Nov 11 at 23:13










  • Thank you for responding so quickly, in the present problem, the same problem, but in the change another problem is presented and it is the next line. if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == 200 ) ) { with this error "Uncaught TypeError: Cannot read property 'readyState' of undefined at XMLHttpRequest.readyStateChange"
    – Filiberto Zaá Avila
    Nov 11 at 23:24










  • As I mentioned in my PD: I have reviewed many threads in this forum and many others but none can explain what is happening or at least do not explain what happens to me
    – Filiberto Zaá Avila
    Nov 11 at 23:25










  • As always, please edit your question to show any recent code changes. It also helps to list those other posts you've looked at and tried to use and explain, if possible, how they have not solved your problem.
    – Phil
    Nov 11 at 23:28
















2















This question already has an answer here:




  • How to access the correct `this` inside a callback?

    8 answers



  • es6 Javascript class using this inside a callback [duplicate]

    2 answers



  • Why does the setInterval callback execute only once?

    2 answers




today I come for the following problem that I'm presenting with a new approach that I want to apply with the Ajax requests.



I have to explain that I commonly work with JQuery this type of requests, but I'm doing some tests with this new approach to see if I can solve some situations that I have not been able to solve with JQuery.



I'm working with a class that I'm developing and with which I'm just starting with the most basic, which is to make a request for plain text.



This is the basic ajax class that I have developed so far.



class Ajax {

constructor () {

this.xhr = null;
if ( XMLHttpRequest ) {

this.xhr = new XMLHttpRequest ();

} else if ( ActiveXObject ) {

try {

this.xhr = new ActiveXObject ( "MSXML2.XMLHTTP" );

} catch ( e ) {

try {

this.xhr = new ActiveXObject ( "Microsoft.XMLHTTP" );

} catch ( e ) {

// throws error log
}
}
}
if ( !this.xhr ) {

alert ( "The browser does not have support to make this type of requests to the server." );
}
}

send ( method, event, url ) {

var textoAjax = "";
this.xhr.open ( method, url, true );
this.xhr.setRequestHeader ( 'X-Requested-With', 'XMLHttpRequest');
this.xhr.setRequestHeader ( "Content-Type", "text/plain" );
this.xhr.onreadystatechange = this.readyStateChange ();
this.xhr.send ( event );
}

readyStateChange () {

if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == "200" ) ) {

document.getElementById ( "responsePhp" ).innerHTML = this.xhr.responseText;
}
}
}

function sendRequest () {

let ajax = new Ajax ();
ajax.send ( "POST", null, "sys/libs/common/PhpAjaxBridge.php" );
}


This is the test html.





<html>
<head>
<meta charset="UTF-8">
<title>Simple Ajax Request</title>
<script type="text/javascript" src="http://localhost/ecomod/indexes/Ajax.js"></script>
</head>
<body>
<div id="responsePhp"></div>
<button onclick="sendRequest();">Send Simple Ajax Request</button>
</body>
</html>


And this is the test php file.



header ( 'Content-type: text/plain' );
echo "Hi. What did you expect? ;P";


The problem is that when I click on the launcher button of my ajax request, although this arrives in my test php file, the answer to that request never arrives. I know that it is strange that there is no return on this request, given that it is a very simple example, but in fact that is the case.



I have tried to make some additional gadget as it is, to make use of the callback functions, but I still do not get an answer.



Here the implementation of the callback.



class Ajax {

constructor () {

this.xhr = null;
if ( XMLHttpRequest ) {

this.xhr = new XMLHttpRequest ();

} else if ( ActiveXObject ) {

try {

this.xhr = new ActiveXObject ( "MSXML2.XMLHTTP" );

} catch ( e ) {

try {

this.xhr = new ActiveXObject ( "Microsoft.XMLHTTP" );

} catch ( e ) {

// throws error log
}
}
}
if ( !this.xhr ) {

alert ( "The browser does not have support to make this type of requests to the server." );
}
}

send ( method, event, url ) {

var textoAjax = "";
this.xhr.open ( method, url, true );
this.xhr.setRequestHeader ( 'X-Requested-With', 'XMLHttpRequest');
this.xhr.setRequestHeader ( "Content-Type", "text/plain" );
this.xhr.onreadystatechange = this.readyStateChange ( this.readyStateChangeCallback );
this.xhr.send ( event );
}

readyStateChange ( callback ) {

callback ( this.xhr.readyState );
}

readyStateChangeCallback ( state ) {

if ( state == 4 ) {

if ( this.xhr.status == 200 ) {

document.getElementById ( "responsePhp" ).innerHTML = this.xhr.responseText;
}
}
}
}

function sendRequest () {

let ajax = new Ajax ();
ajax.send ( "POST", null, "sys/libs/common/PhpAjaxBridge.php" );
}


As you can see here I show you the response from the server, but it never reaches the client



Response Headers



Response Text



What can be happening? What can I be forgetting or forgetting?



Thanks in advance.



PD: I have reviewed many threads in this forum and many others but none can explain what is happening or at least do not explain what happens to me, I have tried any solution that they have presented but none manages to unveil the mystery that it happens to me. :s
Sorry for the length but I wanted to be very explicit and place the code as is with the errors described



update: if I eliminate the parentheses in the line



this.xhr.onreadystatechange = this.readyStateChange ();


as suggested by Phil, the following error occurs




Uncaught TypeError: Cannot read property 'readyState' of undefined at XMLHttpRequest.readyStateChange (Ajax.js:84)




where the line in question is this



if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == 200 ) ) {


On the other hand I must note that this.xhr.readyState only comes to take the value 1. The values 2, 3 and 4 never get to receive










share|improve this question















marked as duplicate by Phil javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 23:03


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • this.xhr.onreadystatechange = this.readyStateChange (); 👈 you're executing the readyStateChange() method here immediately instead of assigning it as a callback. Even if you remove the (), you're still going to run into problems accessing this.
    – Phil
    Nov 11 at 23:01










  • The TL;DR of the duplicate posts is that you want this.xhr.onreadystatechange = () => { this.readyStateChange() }. You might also be interested in the onload event as well as the more modern Fetch API
    – Phil
    Nov 11 at 23:13










  • Thank you for responding so quickly, in the present problem, the same problem, but in the change another problem is presented and it is the next line. if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == 200 ) ) { with this error "Uncaught TypeError: Cannot read property 'readyState' of undefined at XMLHttpRequest.readyStateChange"
    – Filiberto Zaá Avila
    Nov 11 at 23:24










  • As I mentioned in my PD: I have reviewed many threads in this forum and many others but none can explain what is happening or at least do not explain what happens to me
    – Filiberto Zaá Avila
    Nov 11 at 23:25










  • As always, please edit your question to show any recent code changes. It also helps to list those other posts you've looked at and tried to use and explain, if possible, how they have not solved your problem.
    – Phil
    Nov 11 at 23:28














2












2








2








This question already has an answer here:




  • How to access the correct `this` inside a callback?

    8 answers



  • es6 Javascript class using this inside a callback [duplicate]

    2 answers



  • Why does the setInterval callback execute only once?

    2 answers




today I come for the following problem that I'm presenting with a new approach that I want to apply with the Ajax requests.



I have to explain that I commonly work with JQuery this type of requests, but I'm doing some tests with this new approach to see if I can solve some situations that I have not been able to solve with JQuery.



I'm working with a class that I'm developing and with which I'm just starting with the most basic, which is to make a request for plain text.



This is the basic ajax class that I have developed so far.



class Ajax {

constructor () {

this.xhr = null;
if ( XMLHttpRequest ) {

this.xhr = new XMLHttpRequest ();

} else if ( ActiveXObject ) {

try {

this.xhr = new ActiveXObject ( "MSXML2.XMLHTTP" );

} catch ( e ) {

try {

this.xhr = new ActiveXObject ( "Microsoft.XMLHTTP" );

} catch ( e ) {

// throws error log
}
}
}
if ( !this.xhr ) {

alert ( "The browser does not have support to make this type of requests to the server." );
}
}

send ( method, event, url ) {

var textoAjax = "";
this.xhr.open ( method, url, true );
this.xhr.setRequestHeader ( 'X-Requested-With', 'XMLHttpRequest');
this.xhr.setRequestHeader ( "Content-Type", "text/plain" );
this.xhr.onreadystatechange = this.readyStateChange ();
this.xhr.send ( event );
}

readyStateChange () {

if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == "200" ) ) {

document.getElementById ( "responsePhp" ).innerHTML = this.xhr.responseText;
}
}
}

function sendRequest () {

let ajax = new Ajax ();
ajax.send ( "POST", null, "sys/libs/common/PhpAjaxBridge.php" );
}


This is the test html.





<html>
<head>
<meta charset="UTF-8">
<title>Simple Ajax Request</title>
<script type="text/javascript" src="http://localhost/ecomod/indexes/Ajax.js"></script>
</head>
<body>
<div id="responsePhp"></div>
<button onclick="sendRequest();">Send Simple Ajax Request</button>
</body>
</html>


And this is the test php file.



header ( 'Content-type: text/plain' );
echo "Hi. What did you expect? ;P";


The problem is that when I click on the launcher button of my ajax request, although this arrives in my test php file, the answer to that request never arrives. I know that it is strange that there is no return on this request, given that it is a very simple example, but in fact that is the case.



I have tried to make some additional gadget as it is, to make use of the callback functions, but I still do not get an answer.



Here the implementation of the callback.



class Ajax {

constructor () {

this.xhr = null;
if ( XMLHttpRequest ) {

this.xhr = new XMLHttpRequest ();

} else if ( ActiveXObject ) {

try {

this.xhr = new ActiveXObject ( "MSXML2.XMLHTTP" );

} catch ( e ) {

try {

this.xhr = new ActiveXObject ( "Microsoft.XMLHTTP" );

} catch ( e ) {

// throws error log
}
}
}
if ( !this.xhr ) {

alert ( "The browser does not have support to make this type of requests to the server." );
}
}

send ( method, event, url ) {

var textoAjax = "";
this.xhr.open ( method, url, true );
this.xhr.setRequestHeader ( 'X-Requested-With', 'XMLHttpRequest');
this.xhr.setRequestHeader ( "Content-Type", "text/plain" );
this.xhr.onreadystatechange = this.readyStateChange ( this.readyStateChangeCallback );
this.xhr.send ( event );
}

readyStateChange ( callback ) {

callback ( this.xhr.readyState );
}

readyStateChangeCallback ( state ) {

if ( state == 4 ) {

if ( this.xhr.status == 200 ) {

document.getElementById ( "responsePhp" ).innerHTML = this.xhr.responseText;
}
}
}
}

function sendRequest () {

let ajax = new Ajax ();
ajax.send ( "POST", null, "sys/libs/common/PhpAjaxBridge.php" );
}


As you can see here I show you the response from the server, but it never reaches the client



Response Headers



Response Text



What can be happening? What can I be forgetting or forgetting?



Thanks in advance.



PD: I have reviewed many threads in this forum and many others but none can explain what is happening or at least do not explain what happens to me, I have tried any solution that they have presented but none manages to unveil the mystery that it happens to me. :s
Sorry for the length but I wanted to be very explicit and place the code as is with the errors described



update: if I eliminate the parentheses in the line



this.xhr.onreadystatechange = this.readyStateChange ();


as suggested by Phil, the following error occurs




Uncaught TypeError: Cannot read property 'readyState' of undefined at XMLHttpRequest.readyStateChange (Ajax.js:84)




where the line in question is this



if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == 200 ) ) {


On the other hand I must note that this.xhr.readyState only comes to take the value 1. The values 2, 3 and 4 never get to receive










share|improve this question
















This question already has an answer here:




  • How to access the correct `this` inside a callback?

    8 answers



  • es6 Javascript class using this inside a callback [duplicate]

    2 answers



  • Why does the setInterval callback execute only once?

    2 answers




today I come for the following problem that I'm presenting with a new approach that I want to apply with the Ajax requests.



I have to explain that I commonly work with JQuery this type of requests, but I'm doing some tests with this new approach to see if I can solve some situations that I have not been able to solve with JQuery.



I'm working with a class that I'm developing and with which I'm just starting with the most basic, which is to make a request for plain text.



This is the basic ajax class that I have developed so far.



class Ajax {

constructor () {

this.xhr = null;
if ( XMLHttpRequest ) {

this.xhr = new XMLHttpRequest ();

} else if ( ActiveXObject ) {

try {

this.xhr = new ActiveXObject ( "MSXML2.XMLHTTP" );

} catch ( e ) {

try {

this.xhr = new ActiveXObject ( "Microsoft.XMLHTTP" );

} catch ( e ) {

// throws error log
}
}
}
if ( !this.xhr ) {

alert ( "The browser does not have support to make this type of requests to the server." );
}
}

send ( method, event, url ) {

var textoAjax = "";
this.xhr.open ( method, url, true );
this.xhr.setRequestHeader ( 'X-Requested-With', 'XMLHttpRequest');
this.xhr.setRequestHeader ( "Content-Type", "text/plain" );
this.xhr.onreadystatechange = this.readyStateChange ();
this.xhr.send ( event );
}

readyStateChange () {

if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == "200" ) ) {

document.getElementById ( "responsePhp" ).innerHTML = this.xhr.responseText;
}
}
}

function sendRequest () {

let ajax = new Ajax ();
ajax.send ( "POST", null, "sys/libs/common/PhpAjaxBridge.php" );
}


This is the test html.





<html>
<head>
<meta charset="UTF-8">
<title>Simple Ajax Request</title>
<script type="text/javascript" src="http://localhost/ecomod/indexes/Ajax.js"></script>
</head>
<body>
<div id="responsePhp"></div>
<button onclick="sendRequest();">Send Simple Ajax Request</button>
</body>
</html>


And this is the test php file.



header ( 'Content-type: text/plain' );
echo "Hi. What did you expect? ;P";


The problem is that when I click on the launcher button of my ajax request, although this arrives in my test php file, the answer to that request never arrives. I know that it is strange that there is no return on this request, given that it is a very simple example, but in fact that is the case.



I have tried to make some additional gadget as it is, to make use of the callback functions, but I still do not get an answer.



Here the implementation of the callback.



class Ajax {

constructor () {

this.xhr = null;
if ( XMLHttpRequest ) {

this.xhr = new XMLHttpRequest ();

} else if ( ActiveXObject ) {

try {

this.xhr = new ActiveXObject ( "MSXML2.XMLHTTP" );

} catch ( e ) {

try {

this.xhr = new ActiveXObject ( "Microsoft.XMLHTTP" );

} catch ( e ) {

// throws error log
}
}
}
if ( !this.xhr ) {

alert ( "The browser does not have support to make this type of requests to the server." );
}
}

send ( method, event, url ) {

var textoAjax = "";
this.xhr.open ( method, url, true );
this.xhr.setRequestHeader ( 'X-Requested-With', 'XMLHttpRequest');
this.xhr.setRequestHeader ( "Content-Type", "text/plain" );
this.xhr.onreadystatechange = this.readyStateChange ( this.readyStateChangeCallback );
this.xhr.send ( event );
}

readyStateChange ( callback ) {

callback ( this.xhr.readyState );
}

readyStateChangeCallback ( state ) {

if ( state == 4 ) {

if ( this.xhr.status == 200 ) {

document.getElementById ( "responsePhp" ).innerHTML = this.xhr.responseText;
}
}
}
}

function sendRequest () {

let ajax = new Ajax ();
ajax.send ( "POST", null, "sys/libs/common/PhpAjaxBridge.php" );
}


As you can see here I show you the response from the server, but it never reaches the client



Response Headers



Response Text



What can be happening? What can I be forgetting or forgetting?



Thanks in advance.



PD: I have reviewed many threads in this forum and many others but none can explain what is happening or at least do not explain what happens to me, I have tried any solution that they have presented but none manages to unveil the mystery that it happens to me. :s
Sorry for the length but I wanted to be very explicit and place the code as is with the errors described



update: if I eliminate the parentheses in the line



this.xhr.onreadystatechange = this.readyStateChange ();


as suggested by Phil, the following error occurs




Uncaught TypeError: Cannot read property 'readyState' of undefined at XMLHttpRequest.readyStateChange (Ajax.js:84)




where the line in question is this



if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == 200 ) ) {


On the other hand I must note that this.xhr.readyState only comes to take the value 1. The values 2, 3 and 4 never get to receive





This question already has an answer here:




  • How to access the correct `this` inside a callback?

    8 answers



  • es6 Javascript class using this inside a callback [duplicate]

    2 answers



  • Why does the setInterval callback execute only once?

    2 answers








javascript ajax callback es6-class






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 23:51









Phil

95.7k11136155




95.7k11136155










asked Nov 11 at 22:56









Filiberto Zaá Avila

598




598




marked as duplicate by Phil javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 23:03


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Phil javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 23:03


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • this.xhr.onreadystatechange = this.readyStateChange (); 👈 you're executing the readyStateChange() method here immediately instead of assigning it as a callback. Even if you remove the (), you're still going to run into problems accessing this.
    – Phil
    Nov 11 at 23:01










  • The TL;DR of the duplicate posts is that you want this.xhr.onreadystatechange = () => { this.readyStateChange() }. You might also be interested in the onload event as well as the more modern Fetch API
    – Phil
    Nov 11 at 23:13










  • Thank you for responding so quickly, in the present problem, the same problem, but in the change another problem is presented and it is the next line. if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == 200 ) ) { with this error "Uncaught TypeError: Cannot read property 'readyState' of undefined at XMLHttpRequest.readyStateChange"
    – Filiberto Zaá Avila
    Nov 11 at 23:24










  • As I mentioned in my PD: I have reviewed many threads in this forum and many others but none can explain what is happening or at least do not explain what happens to me
    – Filiberto Zaá Avila
    Nov 11 at 23:25










  • As always, please edit your question to show any recent code changes. It also helps to list those other posts you've looked at and tried to use and explain, if possible, how they have not solved your problem.
    – Phil
    Nov 11 at 23:28


















  • this.xhr.onreadystatechange = this.readyStateChange (); 👈 you're executing the readyStateChange() method here immediately instead of assigning it as a callback. Even if you remove the (), you're still going to run into problems accessing this.
    – Phil
    Nov 11 at 23:01










  • The TL;DR of the duplicate posts is that you want this.xhr.onreadystatechange = () => { this.readyStateChange() }. You might also be interested in the onload event as well as the more modern Fetch API
    – Phil
    Nov 11 at 23:13










  • Thank you for responding so quickly, in the present problem, the same problem, but in the change another problem is presented and it is the next line. if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == 200 ) ) { with this error "Uncaught TypeError: Cannot read property 'readyState' of undefined at XMLHttpRequest.readyStateChange"
    – Filiberto Zaá Avila
    Nov 11 at 23:24










  • As I mentioned in my PD: I have reviewed many threads in this forum and many others but none can explain what is happening or at least do not explain what happens to me
    – Filiberto Zaá Avila
    Nov 11 at 23:25










  • As always, please edit your question to show any recent code changes. It also helps to list those other posts you've looked at and tried to use and explain, if possible, how they have not solved your problem.
    – Phil
    Nov 11 at 23:28
















this.xhr.onreadystatechange = this.readyStateChange (); 👈 you're executing the readyStateChange() method here immediately instead of assigning it as a callback. Even if you remove the (), you're still going to run into problems accessing this.
– Phil
Nov 11 at 23:01




this.xhr.onreadystatechange = this.readyStateChange (); 👈 you're executing the readyStateChange() method here immediately instead of assigning it as a callback. Even if you remove the (), you're still going to run into problems accessing this.
– Phil
Nov 11 at 23:01












The TL;DR of the duplicate posts is that you want this.xhr.onreadystatechange = () => { this.readyStateChange() }. You might also be interested in the onload event as well as the more modern Fetch API
– Phil
Nov 11 at 23:13




The TL;DR of the duplicate posts is that you want this.xhr.onreadystatechange = () => { this.readyStateChange() }. You might also be interested in the onload event as well as the more modern Fetch API
– Phil
Nov 11 at 23:13












Thank you for responding so quickly, in the present problem, the same problem, but in the change another problem is presented and it is the next line. if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == 200 ) ) { with this error "Uncaught TypeError: Cannot read property 'readyState' of undefined at XMLHttpRequest.readyStateChange"
– Filiberto Zaá Avila
Nov 11 at 23:24




Thank you for responding so quickly, in the present problem, the same problem, but in the change another problem is presented and it is the next line. if ( ( this.xhr.readyState == 4 ) && ( this.xhr.status == 200 ) ) { with this error "Uncaught TypeError: Cannot read property 'readyState' of undefined at XMLHttpRequest.readyStateChange"
– Filiberto Zaá Avila
Nov 11 at 23:24












As I mentioned in my PD: I have reviewed many threads in this forum and many others but none can explain what is happening or at least do not explain what happens to me
– Filiberto Zaá Avila
Nov 11 at 23:25




As I mentioned in my PD: I have reviewed many threads in this forum and many others but none can explain what is happening or at least do not explain what happens to me
– Filiberto Zaá Avila
Nov 11 at 23:25












As always, please edit your question to show any recent code changes. It also helps to list those other posts you've looked at and tried to use and explain, if possible, how they have not solved your problem.
– Phil
Nov 11 at 23:28




As always, please edit your question to show any recent code changes. It also helps to list those other posts you've looked at and tried to use and explain, if possible, how they have not solved your problem.
– Phil
Nov 11 at 23:28

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Full-time equivalent

Bicuculline

さくらももこ