error in ajax request

Asked

Viewed 21 times

0

Dear friends, good morning!

I have a mistake I can’t fix, log on:

index.html:1 Access to XMLHttpRequest at 'http://meusite.com/testmail.php' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
jquery.min.js:2 Cross-Origin Read Blocking (CORB) blocked cross-origin response http://meusite.com/testmail.php with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.
send @ jquery.min.js:2
ajax @ jquery.min.js:2
(anonymous) @ index.html:302
dispatch @ jquery.min.js:2
v.handle @ jquery.min.js:2

I’ve seen sites reporting the following:

header("Access-Control-Allow-Origin: http://www.website.com");

or even

 Access-Control-Allow-Origin: [seu website] ou Access-Control-Allow-Origin: *

I confess that I do not understand much of network, I do not know where to insert such lines and the articles I read seemed Greek, as in: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin

I couldn’t apply any suggested solution.

my jquery is the following:

$("#formcontato").submit(function(event){
    event.preventDefault(); //prevent default action 
    var post_url = $(this).attr("action"); //get form action url
    var request_method = $(this).attr("method"); //get form GET/POST method
    var form_data = new FormData(this); //Creates new FormData object
    $.ajax({
        url : post_url,
        type: request_method,
        data : form_data,
        contentType: false,
        cache: false,
        processData:false
    }).done(function(response){ 
      console.log(response);
        $("#server-results").html(response);
        $("#formcontato")[0].reset(); 
    });
});

The action I need is done in parts, because my intention is to send an email and this email is sent, but javascript does not return if it was sent successfully and does not even clear the fields. I believe that the execution does not pass the: .done(function(response){

Thanks for the help!

  • CORS blocks the JS from making requests on servers that are in different domains unless this server explicitly allows it. The HTTP header you found should be configured on the server you are ordering in order to allow the domain where your JS is.

  • Thank you very much, but the problem remains

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.