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
1 Answer
Reset to default 2You 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>