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 小贝360-4 配二个 华772S 设置WⅰFi5G 连接
  • ¥15 vs2022的QT报错,好像是缺少winextras
  • ¥15 怎么看 cst中一个面的功率分布图
  • ¥15 c语言数据结构求9999
  • ¥15 Fiddler无法对部分小程序抓包
  • ¥60 Python代码 ip首部检验和计算代码 版本协议 首部长度 源地址 目的地址 存活时间
  • ¥18 微机原理汇编的综合实验
  • ¥15 LD衰减图用R语言对其可视化
  • ¥15 Mermaid语法生成的svg在Axure无法编辑
  • ¥35 Windchill二次开发