L
L
laguna11322018-01-22 12:43:41
PHP
laguna1132, 2018-01-22 12:43:41

What to do with javascript connection on a multi-page site?

Good afternoon. I am developing a multi-page website. Faced such problem:
On the main page I have a slider (carousel). An es6 module is connected to the common script, in which keystrokes are caught. Everything works, but on other pages where there is no this carousel, an error pops up in the console "Cannot read property 'addEventListener' of null". How to decide? Perhaps there is a way to connect modules depending on the page?
5a65b23058d61071371135.png5a65b2356e444869563962.png5a65b239dce06659891351.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
uaf0x, 2019-11-07
@uaf0x

In the handler write:

$json = $_POST['data']; //json need to be data
    $info = json_encode($json);
    $file = fopen('test.json','w+') or die("File not found");
    fwrite($file, $info);
    fclose($file);
  exit;

file_put_contents('test.json', json_encode($_POST['data']));
  exit;

You need to convert the array to json object and write this line.

S
Stanislav, 2018-01-22
@ms-dred

As always

document.querySelector('.reviews_next') && document.querySelector('.reviews_next').addEvent..........

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question