+ Start a Discussion
Hagil BaikHagil Baik 

Vue/Axios/Salesforce: No 'Access-Control-Allow-Origin' header is present on the requested resource (pls help!)

First time using a salesforce web-to-lead form in a vue app. Trying to add axios (requirement for the current project) and am getting back a COR issue:
Failed to load https://ap4.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access.
import axios from 'axios';

export default ({
  name: 'app',
  data() {
    return {
      country: '',
      first_name: '',
      last_name: '',
      email: '',
      company: '',
      URL: '',
      phone: '',
      revenue: '',
      emailOptOut: ''
  methods: {
    submitForm() {
      axios.post('https://ap4.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8', {
        crossdomain: true,

        country: this.country,
        first_name: this.first_name,
        last_name: this.last_name,
        email: this.email,
        company: this.company,
        URL: this.URL,
        phone: this.phone,
        revenue: this.revenue,
        emailOptOut: this.emailOptOut
      }).then(response => {
        this.response = JSON.stringify(response, null, 2)
<div id="app">
 <div class="main">
      <div class="container"> 
        <img src="/images/image.png" alt="">
          <h1>Test Account<br>Sign Up</h1>  
          <form @submit.prevent="submitForm">

        <input type=hidden name="oid" value="webtoformnumber">
        <input type=hidden name="retURL" value="https://www.project.com/thankyou">

<div class="field">
    <label for="country">
  <div class="control">
      <input class="input" id="country" name="country" type="text" v-model= "country" required autocomplete="off">

<div class="field">
  <label for="first_name">First Name</label>
  <div class="control">
    <input class="input" id="first_name" name="first_name" type="text" v-model= "first_name" required autocomplete="off">

<div class="field">
  <label for="last_name">Last Name</label>
  <div class="control">
    <input class="input" id="last_name" name="last_name" type="text" v-model= "last_name" required autocomplete="off">

Pretty new at this so apologise in advance is theres already an answer out there (checked but can't seem to find one for vue/sfdc/axios)
Any help would be greatly appreciated! Thanks!
Hi Hagi.
Mark as best answer, If it resloves !!​
Try using relative url. The error is due to Cross Domain Request..Follow below link

Mark as resloved if it helps :) :)
Bhanu Prakash
visit ForceLearn.com  (https://www.forcelearn.com/)
Hagil BaikHagil Baik
Sorry Bhanu but this doesn't really solve my issue. Thanks for your help though!
Jake Miller 17Jake Miller 17

Did you find a solution for this? I am having the same issue.