Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to fetch API data using POST and GET in PHP

// USING GET
//_____________________________________
//If you want to $_GET['x'], you need to send the data in the querystring:
var url = '/your/url?x=hello';

fetch(url)
.then(function (response) {
  return response.text();
})
.then(function (body) {
  console.log(body);
});
// USING POST
//___________________________________________
//If you want to $_POST['x'], you need to send the data as FormData:

var url = '/your/url';
var formData = new FormData();
formData.append('x', 'hello');

fetch(url, { method: 'POST', body: formData })
.then(function (response) {
  return response.text();
})
.then(function (body) {
  console.log(body);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: bootstrap dropdown doesnt work with angular 12 
Javascript :: javascript append child 
Javascript :: settimeout function javascript for loop 
Javascript :: how to capitalize first letter in javascript 
Javascript :: javascript template literals 
Javascript :: javascript join object properties in array 
Javascript :: discord client.send_message js 
Javascript :: jquery submit form 
Javascript :: how to merge 2 object array by the same key with lodash 
Javascript :: set attribute using each jquery 
Javascript :: how to move div using jquery 
Javascript :: how to check platform in nodejs 
Javascript :: flutter json to class 
Javascript :: for loop in vue 
Javascript :: divisible by 3 javascript 
Javascript :: toastify 
Javascript :: material ui outlined input with icon 
Javascript :: javascript function to open file browser 
Javascript :: jquery list all event listeners 
Javascript :: js platformer 
Javascript :: render markdown in nextjs 
Javascript :: moment js between two dates 
Javascript :: react router dom private route 
Javascript :: javascript validate string with regex 
Javascript :: make copy of date javascript 
Javascript :: iife javascript 
Javascript :: make form submit on new tab using jquery 
Javascript :: define an unsigned int js 
Javascript :: stop a site from reloading javascript 
Javascript :: comparing two arrays in javascript returning differences 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =