Ajax request

Sir I have these codes

<script>                          
function myCall() {

                    var date_filter = $("#datepicker-13").val();

                    alert(date_filter)
                    var request = $.ajax({

                        url: "ajax_arrival.php",
                        type: "Get",
                        date: date_filter,
                        dataType: "html"
                    });


                    request.done(function(msg) {
                        $("#wh_bg1").html(msg);
                        alert(msg);
                    });

                    request.fail(function(jqXHR, textStatus) {
                        alert("Request failed: " + textStatus);
                    });
                }
             
        </script>  

In above codes
alert(date_filter)
says: 29-08-2016

It means this funciton is getting DATE from FORM.

and here ajax_arrival.php for processing

<?php
include_once("includes/connectw.php");

$query ="SELECT * FROM arrival WHERE date='date_filter'";
$result=mysqli_query($con, $query);
if ($result){
$row = mysqli_fetch_array($result); 
$res=$row['qty']."##".$row['weight'];
echo $res; 
}
?>

when I run function myCall()
then it says:

Undefined constant date_filter

why the value of date_filter is not going to ajax_arrival.php?
or is there anyother mistake?

Please help

because you just assume this. the value indeed goes to the script, but you never use it.

in fact, the error comes from the database. and clearly, "date_filter" is not a valid date constant (such as CURRENT_DATE).

sir in my function date_filter is user defined variable.

date_filter as you have it here is a literal meaning that it is not at all a date.
Since you are using get in your ajax, that should be

WHERE date = '".$_GET['date_filter']."'

Thats just one problem I see.

Also

date: date_filter,

probably should be

data: date_filter, ??

Also you may find that you have to rearrange the date you send into the query, depending on how the date column is defined in your table.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.