简体   繁体   English

如何获取ajax值并存储在PHP变量中?

[英]How to get ajax value and store in PHP variable?

custom.js file: custom.js文件:

$(document).ready(function() {
    $("#company_name").keyup(function() {
        $.ajax({
            type: "POST",
            url: "http://localhost/capms_v2/ca_autocomplete/getcompanyName",
            data: {
                keyword: $("#company_name").val()
            },
            dataType: "json",
            success: function(data) {
                //alert(data);
                if (data.length > 0) {
                    $('#DropdownCompany').empty();
                    $('#company_name').attr("data-toggle", "dropdown");
                    $('#DropdownCompany').dropdown('toggle');

                } else if (data.length == 0) {
                    $('#company_name').attr("data-toggle", "");
                }
                $.each(data, function(key, value) {
                    if (data.length >= 0)
                        $('#DropdownCompany').append('<li role="displayCountries" ><a role="menuitem DropdownCompany" id=' + value['company_id'] + ' Address1=' + value['company_address1'] + ' Address2=' + value['company_address2'] + ' city=' + value['company_city'] + ' state=' + value['company_state'] + ' pincode=' + value['company_zip'] + '  class="dropdownlivalue">' +
                            value['company_name'] + '</a></li>');
                });
            }
        });
    });
    $('ul.txtcountry').on('click', 'li a', function() {
        $('#company_name').val($(this).text());
        $('#company_id').val($(this).attr("id"));
        // $('#company_address1').val($(this).text());

        $('#tableCityID').html($(this).attr("id"));
        $('#tableCityName').html($(this).text());
        $('#Address1').html($(this).attr("Address1"));
        $('#Address2').html($(this).attr("Address2"));
        $('#city').html($(this).attr("city"));
        $('#state').html($(this).attr("state"));
        $('#pincode').html($(this).attr("pincode"));
    });
});

I was getting id in span id="tableCityID" but if I store the value and pass the value to mysql it was not fetching the value 我在span id="tableCityID"中获取ID,但是如果我存储该值并将该值传递给mysql,则不会获取该值

$com = '<span id="tableCityID">'; 

and if I echo the select query 如果我回显选择查询

echo $sql="select * from ca_job WHERE job_status!='Closed' AND job_customer_name = '".$com."'";

I get the result with not completed single codes 我得到未完成的单个代码的结果

select * from ca_job WHERE job_status!='Closed' AND job_customer_name = '15

If anybody faces this problem, please help me. 如果有人遇到此问题,请帮助我。 Thanks in advance. 提前致谢。

just use the </span> 只需使用</span>

like this 像这样

$com = '<span id="tableCityID"></span>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM