javascript - ajax function on change dropdown Value - Stack Overflow

Hie Everyone!In PHP page1 my code is here..<html>....<select id="customer">...&l

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>

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..
?>

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.

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>

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..
?>

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.

Share Improve this question asked Mar 17, 2015 at 9:16 PratikshaPratiksha 11 gold badge1 silver badge5 bronze badges 5
  • what output of url page2.php?ID=[some id]? – bekt Commented Mar 17, 2015 at 9:21
  • data: "ID="+id, var Id = $(this).val(); - try with uppercase, fix this: data: "ID="+Id - uppercase 'I'. – sinisake Commented Mar 17, 2015 at 9:21
  • you will give echo infront of the $ID variable <?php echo $ID=$_GET['ID']; ... //db connection code .. $sql="select * from Table1 where id='$ID'"; //result code.. //while loop.. //echo something.. // all working without error.. ?> – Vetrivel Commented Mar 17, 2015 at 9:21
  • Sorry guys..But id and Id problem is just here when I paste my code. It all right in my original page. – Pratiksha Commented Mar 17, 2015 at 9:33
  • Its still not working – Pratiksha Commented Mar 17, 2015 at 9:33
Add a ment  | 

1 Answer 1

Reset to default 2

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..
?>

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745184506a4615572.html

相关推荐

  • javascript - ajax function on change dropdown Value - Stack Overflow

    Hie Everyone!In PHP page1 my code is here..<html>....<select id="customer">...&l

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信