0

When I put var in front of method and url (var method, and var url) the code does not work.

function intervalcheck(theObject) {
  var xmlhttp = new XMLHttpRequest(),
    method = 'POST',
    url = 'https://thekmui.com/payb/payresult/result.php';

  xmlhttp.open(method, url, true);
  xmlhttp.onload = function () {
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
Teera
  • 23
  • 4
  • Because `var a = 1, var b = 2;` is invalid syntax. Read the [documentation](//developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/var). Why would you expect invalid syntax to work? `var a = 1, b = 2;` is correct syntax. Use [Fetch](//developer.mozilla.org/docs/Web/API/Fetch_API/Using_Fetch) instead of `XMLHttpRequest` and use `const` or `let` instead of `var`. – Sebastian Simon Feb 05 '22 at 21:39

1 Answers1

-1

Take a look at here:

var xmlhttp = new XMLHttpRequest(),
    method = 'POST',

You are putting ','(comma) after each line. Either you leave it empty and browser handle the rest. Or you can put ';' semi-colon like this:

 var xmlhttp = new XMLHttpRequest();
    method = 'POST';

Otherwise the code will produce a massive error. You may follow this post as well: Send POST data using XMLHttpRequest

Sohan Arafat
  • 93
  • 2
  • 16