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条)

报告相同问题?

悬赏问题

  • ¥100 ijkplayer使用AndroidStudio/CMake编译,如何支持 rtsp 直播流?
  • ¥20 和学习数据的传参方式,选择正确的传参方式有关
  • ¥15 这是网络安全里面的poem code
  • ¥15 用js遍历数据并对非空元素添加css样式
  • ¥15 使用autodl云训练,希望有直接运行的代码(关键词-数据集)
  • ¥50 python写segy数据出错
  • ¥20 关于线性结构的问题:希望能从头到尾完整地帮我改一下,困扰我很久了
  • ¥30 3D多模态医疗数据集-视觉问答
  • ¥20 设计一个二极管稳压值检测电路
  • ¥15 内网办公电脑进行向日葵