F
F
Fithanso2019-06-10 21:58:17
PHP
Fithanso, 2019-06-10 21:58:17

Problem with Cross-Origin Read Blocking. How to include html file?

Greetings.
In general, we are talking about connecting a widget to a third-party site. The link is inserted like this:

<script src="http://test.meconnect.ru/widget/test123.js" async></script><a href="https://meconnect.ru" style="position:absolute; left:-9999px;" alt="" /></a>

And when the server receives a request for src, it simply parses it and selects a nickname (test123), searches for it in the database, etc. The system was originally written not by me, and it works correctly. The bottom line is that there are two php files - one connects the second. The second contains just html markup (well, the output of a couple of variables using php). The problems started when I decided to uncomment this in the first connecting file with the php extension (and in fact there is 95% of the code in js):
switch($profile_account->template) {

    case 'one'      : 

    include_once 'profile_widget_one.php';
    
    break;
}

header("Content-Type: text/javascript");

The code was written before me. An important point: switch works correctly and includes the correct file.
The problem is that when I run the script, a warning is displayed in the console:
Cross-Origin Read Blocking (CORB) blocked cross-origin response test.meconnect.ru/widget/test123.js with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.
The browser does not allow you to connect the php file! Even if you send him a header: If you send a text/javascript header when connecting, then naturally an error will come out: Uncaught SyntaxError: Unexpected token < I read about it on the Internet, but there everyone has questions with ajax, without php. Can ajax somehow be connected?
header("Content-Type: text/html")

All files are on the same server. HOW TO BE?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya Loginov, 2019-06-10
@Fithanso

The problem is that your php code returns html. You must return content type text/javascript, and the file must contain js code that will already add your widget's html to the page.

N
Nikolai Konyukhov, 2019-06-10
@heahoh

Your content starts to be sent before the header is set
Put a line header("Content-Type: text/javascript");before the uncommented code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question