G
G
greck102014-11-30 14:56:17
PHP
greck10, 2014-11-30 14:56:17

How to make an asynchronous request to collect statistics (JS-PHP)?

Hello.
It is necessary to collect statistics on some parameters of visits. The bottom line is to make an asynchronous script call every time the page is loaded. Did it like this:

<script async="true" src="/stat.php?var=<?=$var?>"></script>

I transfer the necessary information to /stat.php and write it to the database. This works, but there are doubts about the correctness of such a call. And the browser swears at the wrong MIME type. How to do it right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2014-11-30
@BuriK666

in stat.php add
header("Content-Type: application/x-javascript");

I
iliyaisd, 2014-12-01
@iliyaisd

Why not make a normal AJAX request to your page loading script?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question