How to resolve CORB even by adding Access-Control-Allow-Origin

Asked

Viewed 1,578 times

0

I added the instruction header('Access-Control-Allow-Origin: *'); in my php, but I keep seeing the error

jquery.min.js:2 Cross-Origin Read Blocking (CORB) blocked cross-origin sponse http://meusite.com with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more Details.

$("#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(); 
    });
});

I’ve been searching for 3 days and can’t solve it, it’s not lack of effort, I just can’t find content that really solves my problem.

  • CORB is different from CORS, add the javascript request code to the question so it can be analyzed as well, follow a debate on this item https://stackoverflow.com/questions/50873764/cross-origin-read-blocking-corb

  • Thank you, javascript code added

1 answer

0

Return the response with the header 'Access-Control-Allow-Origin: *' Check the code below for the PHP server response.

<?php header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
echo json_encode($phparray); 

you may be making a JSONP request and the server is responding JSON, also puts the content-type in your header, and so your browser may be refusing your treatment...

Browser other questions tagged

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