How can I fetch an html file from my server and embed it into a client page?

Asked

Viewed 76 times

0

I developed a chat, to implement it is necessary to add on the page of the client a . js (So the client does not have the job of creating the markup on his site, just import the js and ready, like any jquery plugin), it works basically like this, there is an html page where he searches the markup(html) and plays inside the client page body, I did it as follows:

This is an example(The original code is larger, but this excerpt summarizes the problem)

var ffchat = ffchat || (function () {
    return {
        addChat: function (Args) {
            $(function () {
                $.get('http://meuhost.com/chat/partial_chat.html', function (data) {
                    var html = $(data);
                    $("body").append(html);
                });
            });
        }
    };
}());

It worked perfectly in my local tests(Same host), the problem is that the browser blocks this request when it is for another host, it prevents me to get the html on my server.

How can I fetch an html file from my server and embed it into a client page?

Remembering that this file has css, js and html to customize the chat on the client page, the chat is in an iframe within this file.

  • Tried to release CORS on your server ?

  • But is this release done on the client machine or on my server? Because if it is on the client machine it does not solve my problem.

  • The release is made on your server. In case your server should say that other sites can send requests to it. In what language your server was made ?

  • created an htacess and put Header Set Access-Control-Allow-Origin "*" , but it didn’t help.

  • After putting this rule, I can’t even access js anymore, I did a quick search on Cors, if you want to post some answers using Cors

  • I’m not sure that’s the problem. And the release of Cors is not standardized for the servers, you would need to know which language you used to also do a survey and be able to answer you better.

  • basically I made a jquery plugin that imports an html, I’m using jquery, the chat is php, but it doesn’t matter since it is inside an iframe.

  • tried with $('body'). load("mypage_page.html"); ?

  • Yes, the effect is the same

Show 4 more comments

1 answer

1

I went through a very similar problem.
At the time I did the following.
I put this code inside my apache2.conf (Below the line where you declare the . htacess)

Header always set Access-Control-Allow-Origin "*"
Header unset Etag

And after that I gave a Re-start on apache2 and it worked normally

  • I can do this same configuration but using . htaccess? Because there are other systems running on this server, larger systems, so I wanted to avoid tampering with the server settings.

Browser other questions tagged

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