ajax open a request
JavaScript
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
//looking for a change or state , like a request or get.
xhttp.onreadystatechange = function() {
//if equal to 4 means that its ready.
// if equal to 200 indicates that the request has succeeded.
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
//GET method for gettin the data // the file you are requesting
xhttp.open("GET", "TheFileYouWant.html", true);
//sending the request
xhttp.send();
}function makeRequest (method, url, data) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.onload = function () {
if (this.status >= 200 && this.status < 300) {
resolve(xhr.response);
} else {
reject({
status: this.status,
statusText: xhr.statusText
});
}
};
xhr.onerror = function () {
reject({
status: this.status,
statusText: xhr.statusText
});
};
if(method=="POST" && data){
xhr.send(data);
}else{
xhr.send();
}
});
}
//GET example
makeRequest('GET', "https://www.codegrepper.com/endpoint.php?param1=yoyoma").then(function(data){
var results=JSON.parse(data);
});
//POST example
var data={"person":"john","balance":1.23};
makeRequest('POST', "https://www.codegrepper.com/endpoint.php?param1=yoyoma",data).then(function(data){
var results=JSON.parse(data);
});
Also in JavaScript:
- Title
- javascript array exists check
- Category
- JavaScript
- Title
- a simple javascript calculator
- Category
- JavaScript
- Title
- how to write regular expression
- Category
- JavaScript
- Title
- how to set up a json file
- Category
- JavaScript
- Title
- export default react
- Category
- JavaScript
- Title
- change select value jquery
- Category
- JavaScript
- Title
- how to make item not dragable in react-sortablejs
- Category
- JavaScript
- Title
- deny ready jquery
- Category
- JavaScript
- Title
- emmet jsx visual studio
- Category
- JavaScript
- Title
- how the filter() function works javascript
- Category
- JavaScript
- Title
- graphql yoga access http headers
- Category
- JavaScript
- Title
- event.persist()
- Category
- JavaScript
- Title
- how to get element by title js
- Category
- JavaScript
- Title
- example of validating fields on your own in express
- Category
- JavaScript
- Title
- enable disable click on div jquery
- Category
- JavaScript
- Title
- change node version
- Category
- JavaScript
- Title
- dumpdata json model dajngo
- Category
- JavaScript
- Title
- add to json object javascript
- Category
- JavaScript
- Title
- how to attach javascript to html
- Category
- JavaScript
- Title
- array reverse algorithm in js
- Category
- JavaScript
- Title
- discord js bot leave voice channel
- Category
- JavaScript
- Title
- add countdown timer to javascript quiz
- Category
- JavaScript
- Title
- error Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class.
- Category
- JavaScript
- Title
- javascript canvas reset transform
- Category
- JavaScript
- Title
- does a function inside a function need to be called?
- Category
- JavaScript
- Title
- adding element to array javascript
- Category
- JavaScript
- Title
- dropzone add download button addedfile
- Category
- JavaScript
- Title
- angular ng-click toggle class
- Category
- JavaScript
- Title
- cascading dropdown for forms react
- Category
- JavaScript
- Title
- interceptor in angular 8
- Category
- JavaScript
- Title
- javascript class constructor
- Category
- JavaScript
- Title
- javascript change url without reload
- Category
- JavaScript
- Title
- html javascript redirect
- Category
- JavaScript
- Title
- array unique values javascript
- Category
- JavaScript
- Title
- check if checkbox is checked jquery
- Category
- JavaScript
- Title
- declaration fonction javascript
- Category
- JavaScript
- Title
- check if a key exists in an object javascript
- Category
- JavaScript
- Title
- double function call javascript
- Category
- JavaScript
- Title
- capitalize all letters jquery
- Category
- JavaScript
- Title
- javascript capitalize string
- Category
- JavaScript
- Title
- array find method javascript
- Category
- JavaScript
- Title
- clear cookies js
- Category
- JavaScript
- Title
- div background image chnage uisng js
- Category
- JavaScript
- Title
- add class javascript
- Category
- JavaScript
- Title
- check the doc name in javascript
- Category
- JavaScript
- Title
- javascript append element to array
- Category
- JavaScript
- Title
- how to make a factorial function in javascript
- Category
- JavaScript
- Title
- discord.js wait seconds
- Category
- JavaScript
- Title
- isogram
- Category
- JavaScript
- Title
- javascript anagram check
- Category
- JavaScript
- Title
- 2 taps is required to close keyboad in react native
- Category
- JavaScript
- Title
- install vue-cli
- Category
- JavaScript
- Title
- generate thumbnail of pdf using pf js
- Category
- JavaScript
- Title
- get selected value of dropdown in javascript
- Category
- JavaScript
- Title
- how to convert array to uppercase in javascript
- Category
- JavaScript
- Title
- average of an array js
- Category
- JavaScript
- Title
- How to get row index and cellindex together in javascript
- Category
- JavaScript
- Title
- google script get name of google form
- Category
- JavaScript
- Title
- dotenv not loading process.env in node
- Category
- JavaScript
- Title
- $(document).on in javascript
- Category
- JavaScript
- Title
- addEventListener
- Category
- JavaScript
- Title
- how to right text with js
- Category
- JavaScript
- Title
- adding a variable to a string without using + in javascript
- Category
- JavaScript
- Title
- get text selected option jquery
- Category
- JavaScript
- Title
- alphabet array js
- Category
- JavaScript
- Title
- how to build a string javascript es6
- Category
- JavaScript
- Title
- add and remove class in jquery
- Category
- JavaScript
- Title
- como criar uam seessão com jsp
- Category
- JavaScript
- Title
- add multiple images inside the DOM js
- Category
- JavaScript
- Title
- column.footer jquery
- Category
- JavaScript
- Title
- Cannot deserialize the current JSON array (e.g. [1,2,3]) into type
- Category
- JavaScript
- Title
- find the last occurrence of a character in a string javascript
- Category
- JavaScript
- Title
- check if file exists javascript
- Category
- JavaScript
- Title
- detox scroll to element
- Category
- JavaScript
- Title
- include gif in react
- Category
- JavaScript
- Title
- deploy angular app on google app engine
- Category
- JavaScript
- Title
- how to push values in array
- Category
- JavaScript
- Title
- clear input field value javascript
- Category
- JavaScript
- Title
- how to Write a program that simulates a coin toss using random method of Javascript Math class
- Category
- JavaScript
- Title
- javascript check if argument is passed
- Category
- JavaScript
- Title
- how reliable is js hasownproperty
- Category
- JavaScript
- Title
- angular material table
- Category
- JavaScript
- Title
- How to change htm h1 from nodejs
- Category
- JavaScript
- Title
- age calculator javascript
- Category
- JavaScript
- Title
- javascript check if string is json parsable
- Category
- JavaScript
- Title
- How do I get Month and Date of JavaScript in 2 digit format
- Category
- JavaScript
- Title
- delete from array javascript
- Category
- JavaScript
- Title
- javascript add row to table
- Category
- JavaScript
- Title
- ionic status bar color
- Category
- JavaScript
- Title
- google auth.onstatechange
- Category
- JavaScript
- Title
- check first two number jquery
- Category
- JavaScript
- Title
- javascript change query parameter without reloading
- Category
- JavaScript
- Title
- fsharp newtonsoft json deserialize
- Category
- JavaScript
- Title
- how to make a div scrollable
- Category
- JavaScript
- Title
- declarar una funcion javascript
- Category
- JavaScript
- Title
- window location in react
- Category
- JavaScript
- Title
- iterate array javascript
- Category
- JavaScript
- Title
- arrow function component react shortcut vscode
- Category
- JavaScript
- Title
- casl react
- Category
- JavaScript
- Title
- callback function javascript
- Category
- JavaScript