HTML + JS:
<script> 
    $(document).ready(function() {
        $('#hit').click(function() { 
   var getURL = $('.cena_vozila_avtonet')[0].value;
   console.log(getURL);
    $.ajax({
                    type: "GET",
                    url: "checkprice.php",
                    data: {naslov: getURL},
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        var res = cena_vozila;
      console.log(cena_vozila);
     }
      });
        });
    });
        
</script><div id="search">
  <input id="term" type="text" value="enter your search" class="cena_vozila_avtonet" />
  <button id="hit" type="button" name="">Search</button>
</div> is not working, with defined checkprice.php, which code is:
<?php
$URL = $_GET['naslov'];
$getURL = file_get_contents($URL);
$dom = new DOMDocument();
@$dom->loadHTML($getURL);
$xpath = new DOMXPath($dom);
$cena_vozila = $xpath->evaluate('//p[contains(@class,"OglasDataCenaTOP")]')->item(0)->nodeValue;
echo $cena_vozila;
?>
What this all should be doing is: Get input from visitor (URL) pass variable to PHP, load DOM and with XPath get a class for div which contains price and return to website.
Now, the part (PHP) which loads DOM elements and gets the price works.
I have issues with AJAX communication between website and PHP. Errors I get in PHP are:
PHP Notice:  Undefined index: naslov in on line 2
PHP Warning:  file_get_contents(): Filename cannot be empty in on line 4
PHP Notice:  Trying to get property of non-object in  on line 9
I understand the values on line 4 and 9. What is wrong on line 2? I`ve specified naslov.
GET/POST <- none of this methods work.
How would I return PHP variable back to site?
 
    