dimanche 5 décembre 2021

How do I solve the error of forcing a call to https in javascript?

How do I solve the error of forcing a call to https in javascript?

Here is my sse source.

const eventInit = () => {

    console.log("eventInit called");
    const url = `${_EVENT_PUSH_ENDPOINT}/itf/subscribe`
    //subscribe to the event
    var httpRequest = new XMLHttpRequest();
    httpRequest.open("GET",url, true);
    httpRequest.setRequestHeader("Accept", "text/event-stream");
    httpRequest.send();
const eventSource = new EventSource(url);

    eventSource.onopen = (event) => {
        console.log('sse open');
    }

    eventSource.onerror = (event) => {
        if (event.readyState == EventSource.CLOSED) {
            console.log('sse close');
        } else {
            console.log("onerror", e);
        }
    }

    eventSource.addEventListener('myEvent', function (event) {
        const data = JSON.parse(event.data);
        if(data.positionYn == "Y"){
        data.dvcStatus = data.poiStatus
            init();
           soundControl.control(data)
            drawHtml.eventListViewer(data); // Draw the list of viewers
        }
    }, false);

}

At this time, the following error occurs.

eventCtrl.js?v=1.6:87 Uncaught ReferenceError: e is not defined
    at EventSource.eventSource.onerror(eventCtrl.js?v=1.6:87)
eventSource.onerror @ eventCtrl.js?v=1.6:87
error (asynchronous)
eventInit @ eventCtrl.js?v=1.6:83
(anonymous) @ index.js:495
:8330/itf/subscribe:1 GET https://localhost:8330/itf/subscribe net::ERR_SSL_PROTOCOL_ERROR

output the url in the chrome developer tools,

url
'http://localhost:8330/itf/subscribe'

It outputs normally, but inside JavaScript, it continues to call https://localhost:8330/itf/subscribe.

I don't know why it calls https even though the url is http.

I am wondering how can I solve this problem.

Best Regards!

Aucun commentaire:

Enregistrer un commentaire