dongxieting9623 2014-04-28 06:58
浏览 48
已采纳

如何通过ajax自动完成在文本框中传递值并在php处理页面中接收

these are my two textboxes

<input name="temp" type="text" id="authnames" />
<input name="qot" type="text" id="qid"  value=""/>

and i am gettting value in the first textbox, i can see it in screen (the one with id authnames)

now i need to pass that value to via jquery/ajax to a new php page and need to retrieve it there below is my jquery/ajax code, and see the way i am passing it, is this the correct way, coz idont think i am getting any value in autocompletequote.php, what am i doing wrong?

$(document).ready(function(){
    $("#qid").autocomplete({
        source: "autocompletequote.php",
        minLength: 1,
        data: { postcode: $("#authnames").val(),
        type: "post",
        dataType: "json", 
        success: function(data) {
            console.log( data );
            console.log("hi");
        }
    },
    select: function (event, ui) {
        var label = ui.item.label;
        var value = ui.item.value;
        //alert(label);
        alert(value);
    }
});
});

there are the two codes i used to retrieve value value in "authnames"

$author = $_POST['postcode'];

and

$author = $_GET['postcode'];

is this correct too?

i have written 2 queries in autocomplete.php

one query do not need value of $author and other needs value of $author,

first query is working fine second is not working its returning null

please help me

  • 写回答

2条回答 默认 最新

  • douchuxun4162 2014-04-28 12:33
    关注

    finally i got the answer i just changed the code to this

    <script>
    var label;
    var value;
     $(document).ready(function(){
    
                    $("#tag").autocomplete({
                        source:'autocomplete.php',
                        minLength:1,
                        select: function (event, ui) 
                        {
                             label = ui.item.label;
                             value = ui.item.value;
                            $("#authnames").val(value);
                            console.log("hi");
    
                            //alert(label);
                            alert(value);
    
                            $("#qid").autocomplete({
                           source:'autocompletequote.php?postcode='+value,
                           minLength:1,
                           select: function (event, ui) 
                           {
                            var label1 = ui.item.label;
                            var value1= ui.item.value;
    
                            console.log("hi");
    
                            //alert(label);
                            //alert(value);
                           }
    
    
                       });
    
                        }
    
    
                    });
    
    
    
                });
    
    
    
    
    </script>
    

    now everything is A OK

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大