Reputation: 13
I'm struggeling with making an AJAX url inside of an php echo. Other troubleshooters around the internet didn't get me through it. Here is my code:
<script type="text/javascript">
$(document).ready(function () {
$.ajaxSetup ({
cache: false
});
var ajax_load = "";
$( "#'.$row_items['id_aanbod'].'" ).change(function() {
$("#res").html(ajax_load).load("update.php", "e=" + $("#'.$row_items['id_aanbod'].'").val() & "id=" + $("#hrr").attr("id"));
});
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
The strange thing is that if I use only one variable the script works like it should, but as soon as I insert the second part there is nothing happening. Can anyone help me with this?
Upvotes: 1
Views: 120
Reputation: 1236
Please try like this:
<script type="text/javascript">
$(document).ready(function () {
$.ajaxSetup ({
cache: false
});
var ajax_load = "";
$( "#<?=$row_items['id_aanbod']?>" ).change(function() {
$("#res").html(ajax_load).load("update.php", "e="+$("#<?=$row_items['id_aanbod']?>").val() + "&id=" + $("#hrr").attr("id"));
});
});
Don't forget to check vals. If short open tags is OFF -> then try :
<?php echo $row_items['id_aanbod']?>
Upvotes: 1
Reputation: 160833
& "id="
should be
+ "&id="
But for clean code, you could write like below:
$("#<?php echo $row_items['id_aanbod']?>").change(function() {
$("#res").html(ajax_load).load("update.php", {
e: this.value,
id: $("#hrr").attr("id")
});
});
Upvotes: 1