Jump to content

Can javascript change the variable value via the byref like au3?


Letraindusoir
 Share

Recommended Posts

Reference website:

https://www.quanzhanketang.com/ajax/tryajax_header.html?filename=tryajax_header

Reference Code:

<!DOCTYPE html>
<html>
<body>

<p>The getAllResponseHeaders() function returns the header information of a resource, like length, server-type, content-type, last-modified, etc.</p>

<button onclick="loadDoc()">Get header information</button>

<p id="demo"></p>

<script>
function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById("demo").innerHTML = xhttp.getAllResponseHeaders();
    }
  };
  xhttp.open("GET", "ajax_info.txt", true);
  xhttp.send();
}
</script>

</body>
</html>

I modify it as follows:

<!DOCTYPE html>
<html>
<body>

<p>The getAllResponseHeaders() function returns the header information of a resource, like length, server-type, content-type, last-modified, etc.</p>

<button onclick="loadDoc()">Get header information</button>

<p id="demo"></p>

<script>
var arh="";
function requery() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
       arh = xhttp.getAllResponseHeaders();
    }
  };
  xhttp.open("GET", "ajax_info.txt", true);
  xhttp.send();
}
function loadDoc(){
  requery();
  document.getElementById("demo").innerHTML = arh;}
</script>

</body>
</html>

Results can be obtained, but need click twice, not sure why.....

Modify it once again as follows:

<!DOCTYPE html>
<html>
<body>

<p>The getAllResponseHeaders() function returns the header information of a resource, like length, server-type, content-type, last-modified, etc.</p>

<button onclick="loadDoc()">Get header information</button>

<p id="demo"></p>

<script>
arh="";
function requery(header) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function(header) {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      header=xhttp.getAllResponseHeaders();
    }
  };
  xhttp.open("GET", "ajax_info.txt", true);
  xhttp.send();
}
function loadDoc(){
  requery(arh);
  document.getElementById("demo").innerHTML = arh;}
</script>

</body>
</html>

but no result.

if Au3,

function requery(byRef header) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function(header) {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      header=xhttp.getAllResponseHeaders();
    }
  };
  xhttp.open("GET", "ajax_info.txt", true);
  xhttp.send();
}

it can use the function 'requery' to change the value of the-address-parameter 'header', but do not know how with js

Please share  experiences with me,

more thanks in advance!

Edited by Letraindusoir
Link to comment
Share on other sites

You can change global variable data or object and set new data or even better make a return if that is available.  Note that your question is on wrong place, this is autoit help and support part of forum, not a javascript support :) .

https://stackoverflow.com/a/7744623/1775164

Note that your calling 

innerHTML = arh;

probably before data is fetched, 

so delite that line and put

document.getElementById("demo").innerHTML = header;

right after

header=xhttp.getAllResponseHeaders();

or use https://javascript.info/async-await

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

  • Developers

What does this thread have to do with AutoIt3 at all, so why post the quest here?

Jos

 

moved

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

15 hours ago, bogQ said:

 Note that your question is on wrong place, this is autoit help and support part of forum, not a javascript support :) .

The two are not contradictory.
some au3-udf related to web page operations such as IE.au3,selenium, sometimes need to introduce JS with execScript or eval.
Learn from each other and Perfect it together...:)
Link to comment
Share on other sites

16 hours ago, bogQ said:

You can change global variable data or object and set new data or even better make a return if that is available.  Note that your question is on wrong place, this is autoit help and support part of forum, not a javascript support :) .

https://stackoverflow.com/a/7744623/1775164

Note that your calling 


innerHTML = arh;

probably before data is fetched, 

so delite that line and put


document.getElementById("demo").innerHTML = header;

right after


header=xhttp.getAllResponseHeaders();

or use https://javascript.info/async-await

Search from web, some say that it can work if change the asynchronous submission to synchronous submission.

more thanks!

Link to comment
Share on other sites

  • Moderators
13 hours ago, Letraindusoir said:
Learn from each other and Perfect it together...:)

Much like asking a Toyota group about why your Ford won't start. Just because they are both car groups doesn't mean you're asking the question in the right place.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...