Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to make a post request from axios

import axios from 'axios';

async makeRequest() {
  try {
    const response = await axios.post('your_request_url_here', {
    // Enter your body parameters here
    });
  }
  catch(e) {
    // Handle your error here
  }
}

// Axios returns a promise and hence you can use .then(), .catch for error
// handling if you don't want to use async/await(use try/catch for error 
// handling)
Comment

axios post request javascript

const createPostRequest = async () => {
	try{
		const { data } = await axios.post(url, body_data, {
		   headers: {
	    	 'Authorization': `Basic ${token}`
		   },
		})
    
	    console.log(data)
	} catch (error) {
		console.log(error)
	}
}

createPostRequest();
Comment

how to use post method axios

 const handleClick = async () => {
    let fd = new FormData();
    fd.append("name", name);
    fd.append("password", password);
    const rep = await axios
      .post("http://localhost/php/api/students/create.php", fd)
      .catch((err) => {
        console.log(err, "axios error");
      });
    console.log(rep.data);
  };
Comment

axios post method

const onSubmit = async (FormData) => {
  FormData.bFlats = meters;
  try {
    let res = await axios({
      method: 'post',
      url: 'http://localhost:5000/api/v1/buildings',
      data: FormData
    });

    console.log(res.data);
    if (res.data.status === 'success') {
      alert("Successfully Inserted");
      reset();
    }
  } catch (error) {
    console.log(error.response.data.message); // this is the main part. Use the response property from the error object
  }
}
Comment

Send Data Using Axios


import Axios from "axios";

var res = await Axios.post('/search', {searchTerm: 'searchTerm'});
Comment

axios send payload in get request

axios.get('/api/updatecart', {
  params: {
    product: this.product
  }
}).then(...)
Comment

Send Axios With Post

async    function send()
    {


        let data = new FormData();     
        data.append("title", "title ???");  
        data.append("note", "note");
        data.append("csrfmiddlewaretoken", '{{csrf_token}}') // 3
        let res =  await  axios.post("/blog/third", data);
        
     
console.log(res.data.my_data);
    }


def third(request):
    if request.method=="POST":
        title = request.POST["title"] 
        note = request.POST["note"] 
        
        
        data = {
                'my_data': title
        }
        
        return JsonResponse(data)
#much simpler than fetch
Comment

PREVIOUS NEXT
Code Example
Javascript :: E: Unable to locate package npm 
Javascript :: MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 
Javascript :: how to turn a number negative in javascript 
Javascript :: node.js f string 
Javascript :: prevent a page from refreshing in react 
Javascript :: js convert special characters to html entities 
Javascript :: js convert html to text 
Javascript :: count array in javascript 
Javascript :: how to serialize form data in js 
Javascript :: javascript index of min value in array 
Javascript :: btn.addeventlistener 
Javascript :: react js create element 
Javascript :: js function pick properties from object 
Javascript :: js querySelectorAll map sample 
Javascript :: js read from json1 
Javascript :: how to get file extension in javascript 
Javascript :: perform database transaction with sequelize 
Javascript :: copy text to clipboard javascript without input 
Javascript :: get first day of the week of a given date javascript js 
Javascript :: how to get selected value of dynamically created dropdown in jquery 
Javascript :: set date to input date js 
Javascript :: remove property from javascript object 
Javascript :: how to control playback speed in javascript 
Javascript :: how to kill all node processes in windows 
Javascript :: javascript alphabet array 
Javascript :: p5js cdn 
Javascript :: for loop on a array 
Javascript :: javascript minimum number in array 
Javascript :: How to call a c# functio from Javascript 
Javascript :: node read file sync 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =