更改下拉列表上的ajax函数值 [英] ajax function on change dropdown Value

查看:55
本文介绍了更改下拉列表上的ajax函数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!在PHP page1中,我的代码在这里.

Hie Everyone! In PHP page1 my code is here..

    <html>
    .
    ...
    <select id="customer">...</select>
    ..
    ....
    <div id="show"></div>
    //and Java script function (ajax call)
   <script>
   $('#customer').change(function(){
        var Id = $(this).val();
    $.ajax({
        type: "GET",
        url: "page2.php",
        data: "ID="+id,
        success: function( data ) {
            document.getElementById("show").innerHTML = data;
        }
    });
    });
    </script>
    </html>

在php page2中作为代码.

In php page2 as code..

<?php
$ID=$_GET['ID'];
...
//db connection code
..
$sql="select * from Table1 where id='$ID'";
//result code..
//while loop..
//echo something..
// all working without error..
?>

因此,当我尝试执行此操作时.它不显示成功数据,或者可能是Ajax函数不起作用.但不会发出任何警报.请帮忙.

So, when I was trying to do this.It does not showing the success data or may be Ajax function not work.I had check with alert(data); but does not Alert anything. please help.

推荐答案

您将在$ get_id变量的前面给出echo.但是,请确保page2.php页面中只有一个回显.

You will give echo infront of the $get_id variable. But you will make sure only one echo in the page2.php page.

<?php
echo $get_id=$_GET['pass_id'];
...
//db connection code
..
$sql="select * from Table1 where id='$get_id'";
//result code..
//while loop..
//echo something..
// all working without error..
?>

然后在page1.php中检查您的ajax响应.使用警报功能.

Then in page1.php check your ajax response. using alert function.

 <script>
   $('#customer').change(function(){
        var id = $(this).val();
    $.ajax({
        type: "GET",
        url: "page2.php",
        data: "pass_id="+id,
        success: function( data ) {
              alert(data);

            document.getElementById("show").innerHTML = data;
        }
    });
    });
    </script>

这篇关于更改下拉列表上的ajax函数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆