1

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?

8
  • 1
    Where is $row_items['id_aanbod'] coming from? A database result? You should <?php echo $row_items['id_aanbod'];?> inside the jquery selector. Commented Apr 17, 2015 at 13:41
  • 2
    Why not just read the documentation for load, and you'll see that it doesn't accept a second argument consisting of a querystring. If you want to send data, add it to the url. Commented Apr 17, 2015 at 13:41
  • wheres the error, how is it not working? errors in dev console? are php errors turned on? Commented Apr 17, 2015 at 13:42
  • the "&" has to be inside the string?! Something like: "$("#res").html(ajax_load).load("update.php", "e=" + $("#'.$row_items['id_aanbod'].'").val() + "&id=" + $("#hrr").attr("id"));"... maybe? Commented Apr 17, 2015 at 13:42
  • @adeneo I'm pretty sure you can use a query string there. As it is a short-hand method for $.ajax() with some added functionalities, the data parameter can be both a query string (correctly encoded obviously...) or an object. Commented Apr 17, 2015 at 13:49

2 Answers 2

1

& "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")
    }); 
});
Sign up to request clarification or add additional context in comments.

Comments

1

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']?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.