How to put the value of a field acquired with jquery in php?

Asked

Viewed 32 times

0

I want to do a try check as parameter the date of a datepicker and the id of an item.

        <script>
            $('.menu-item').click(function() {  

              var item = $(this).attr('value');
              alert(item);
            });
        </script>

         <script>
        $("#delivery_time").click(function() {   

            $.ajax
                    ({
                        beforeSend: function () {
                            $("#oi").html("Carregando...");
                        },
                        success: function ()
                        {

                            var datahora = $("#delivery_date").val();
                            <?php 

                            //Conexao ao banco e contator 
                                    $conecta = mysqli_connect("localhost", "root", "","alugaq")or die("Erro ao conectar!");
                                    $sql = "SELECT * FROM 'mt_order' WHERE 'merchant_id' LIKE '%$merchant_id%' AND 'item_id' LIKE '%$item%' AND 'delivery_date' LIKE '%$data%'" ;
                                    $query = mysqli_query($conecta,$sql);
                                    $qtd = mysqli_num_rows($query);       
                            ?>
                            alert($(".ui-state-default:contains('00')").css('display','none'));
                            alert(datahora);
                            alert(item);
                            alert(<?php echo $qtd ;?>);

                        }


                    });


    });
    </script>

I need the item variable and the datatime variable to work in the query, but I don’t know how to put the variables of Java in php.

  • No man, you can not use php so inside javascript, what you have to do is pass a variable to a php page via ajax and get the return.

  • Look, two examples of ajax in answers I gave you a few days ago, might help you: http://answall.com/questions/109904/como-passar-dados-para-uma-funcao-php-pela-url-ajax/173967#173967 http://answall.com/questions/170469/filtro-c-ajax-php/170723#170723

  • After the page is sent, the javascript is in the person’s browser and there is no way to run php there. That’s why ajax sends the data to the server and takes a result back to be used in the javascript that is running in the browser.

  • jquery-1.10.2.min. js:6 Synchronous Xmlhttprequest on the main thread is deprecated because of its detrimental effects to the end user’s Experience. For more help, check https://xhr.spec.whatwg.org/. This was the error you made trying

  • This is a warning. Send this var item by ajax to an if(isset($_post['item'])) and there define it in the query, take the return and display it the way you want. Return only comes in text form.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.