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

如何通过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条)

报告相同问题?

悬赏问题

  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同