Reputation: 7
I have a error on ajax data:value see my code
<script>
$(document).ready(function(){
$("#pros").change(function(e){
e.preventDefault()
var value = $("#pros").val();
$.ajax({
type: "GET",
url: "product.php",
dataType: "html",
data: value,
success: function(msg){
$("#products").html(msg);
}
});
});
});
</script>
when i pass the value to product page then when i echo I get error Undefined index: value product.php on line 2 product.php page
$q = $_GET['value'];
echo $q;
Upvotes: 0
Views: 134
Reputation: 2841
<script>
$(document).ready(function(){
$("#pros").change(function(e){
e.preventDefault()
var value = $("#pros").val();
$.ajax({
type: "GET",
url: "product.php",
dataType: "html",
data: {'value':value},
success: function(msg){
$("#products").html(msg);
}
});
});
});
</script>
Upvotes: 0
Reputation: 318202
$(document).ready(function () {
$("#pros").on('change', function (e) {
e.preventDefault()
$.ajax({
type: "GET",
url : "product.php",
dataType: "html",
data: {value: this.value} //key / value
}).done(function(msg) {
$("#products").html(msg);
});
});
});
Upvotes: 1
Reputation: 22817
You have to send an hash:
$.ajax({
type: "GET",
url: "product.php",
dataType: "html",
data: { 'value' : $("#pros").val() },
success: function(msg){
$("#products").html(msg);
}
});
Notice { 'value' : $("#pros").val() }
.
Upvotes: 1