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

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波