Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
I want a post request from javascript to php across different domain. CORS error, header origin error

So I have an ajax request:

$.ajax({
  url: "some url different domain/transfer.php",
  headers: {
    "Access-Control-Allow-Origin": "*",
  },
  type: "post",
  dataType: "json",
  success: function (msg) {
    console.info(msg);
    gfg = msg;
    console.log(gfg);
  },
});

and this is the header of my transfer.php file-

<?php
header('content-type: application/json; charset=utf-8');
header("access-control-allow-origin: *");

So after working for more than 2 days I am having an error:

Access to XMLHttpRequest at 'some URL different domain/transfer.php' from origin 'http://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I have tried also tried "jsonp" instead of JSON type but in that case, it gives me an error: "<? unidentified token in 1st line" which is obviously necessary for PHP.

Pleaseeeeee anyone on this planet can help me to make a post/get request using js to PHP (I am receiving an array from PHP). Before I burn my laptop :) Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Add on your server Access-Control-Allow-Origin: *

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!