zoukankan      html  css  js  c++  java
  • fetch VS AJAX

    fetch('https://mywebsite.com/endpoint/', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ firstParam: 'yourValue', secondParam: 'yourOtherValue', }) })

    fetch("/data.json").then(function(res) {
    if (res.ok) {
    res.json().then(function(data) {
    console.log(data.entries);
    });
    } else {
    console.log("Looks like the response wasn't perfect, got status", res.status);
    }
    }, function(e) {
    console.log("Fetch failed!", e);
    });

    'Accept': 'application/json',
    'Content-Type': 'application/json

    fetch("http://www.example.org/submit.php", {
    method: "POST",
    headers: {
    "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
    },
    body: "firstName=Nikhil&favColor=blue&password=easytoguess"
    }).then(function(res) {
    if (res.ok) {
    alert("Perfect! Your settings are saved.");
    } else if (res.status == 401) {
    alert("Oops! You are not authorized.");
    }
    }, function(e) {
    alert("Error submitting form!");
    });

  • 相关阅读:
    [CF703D] Mishka and Interesting sum
    [CF1454F] Array Partition
    [CF13E] Holes
    [CF1110D] Jongmah
    [CF1204D2] Kirk and a Binary String
    [CF936B] Sleepy Game
    [CF546E] Soldier and Traveling
    [CF1025D] Recovering BST
    [CF598C] Nearest vectors
    [CF988E] Divisibility by 25
  • 原文地址:https://www.cnblogs.com/jayruan/p/5406461.html
Copyright © 2011-2022 走看看