hi guys, can anyone advise me how to pass ajax post, my alert message has value but i cant pass to index.php .

searchresult.php

<input class="lowfliter" onclick="lowprice()" type="submit" id="lprice" name="lprice" value="Lowest">

search.js

function lowprice() {

        var lprice = document.getElementById("lprice").value;           

        var myData = 'lprice='+lprice;

            jQuery.ajax({
            type: "POST", // HTTP method POST or GET
            url: "index.php", //Where to make Ajax calls
            dataType:"text", // Data type, HTML, json etc.
            data:myData, //Form variables
            success:function(){

            alert(lprice);    

            },  
            });  

          document.getElementById("myNav").style.display = "block";
    }

    function closeoverlay() {
          document.getElementById("myNav").style.display = "none";
    }

passvalue.png

index.php

<?php
if(isset($_POST['lprice']))
{
echo $lowest = $_POST['lprice'];
}
?>

<div id="myNav" class="overlay">
    <a href="javascript:void(0)" class="closebtn" onclick="closeoverlay()"><i class="fa fa-close"></i></a>
      <div class="overlay-content">
        <a href="#" style="color:#FFF; font-size:18px;"><?php echo $lowest ?></a>
        <a href="#">Services</a>
        <a href="#">Clients</a>
        <a href="#">Contact</a>
      </div>
</div>

Try setting data as an array, as so:

    $.ajax({
        type: 'POST',
        url: 'index.php',
        data: { lprice: lprice },
        dataType: 'text',       
    });

Try using console.log(lprice) right efore the ajax request to print out the value of lprice and make sure that lprice is being accurately retrieved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.