Answers for "ajax using js"

3

ajax request in javascript

fetch('https://api.covid19api.com/summary')
            .then(response => response.json())
            .then(data => console.log(data))
            .catch(err => {
                console.log(err)
            });
Posted by: Guest on May-19-2021
6

ajax syntax in javascript

var id = empid;

$.ajax({
    type: "POST",
    url: "../Webservices/EmployeeService.asmx/GetEmployeeOrders",
    data: "{empid: " + empid + "}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(result){
        alert(result.d);
        console.log(result);
    }
});
Posted by: Guest on September-30-2020
2

js ajax

// For a plain JS solution, use these functions:

function _GET_REQUEST(url, response) {
  var xhttp;
  if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
  } else {
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }

  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      response(this.responseText);
    }
  };

  xhttp.open("GET", url, true);
  xhttp.send();
}

function _POST_REQUEST(url, params, response) {
  var xhttp;
  if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
  } else {
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }

  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      response(this.responseText);
    }
  };

  xhttp.open("POST", url, true);
  xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xhttp.send(params);
}

// and apply like this:
_GET_REQUEST('http://someurl', (response) => {
	// do something with variable response
});
_POST_REQUEST('http://someurl', 'paramx=y', (response) => {
	// do something with variable response
});
Posted by: Guest on October-25-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language