Question

I am trying to load a div with .load(). I have tried:

function newPage(p_id){
    var id = p_id;
    $("#div").load("content.php?id=id");

}

Now php does not receive the value of id, but the string "id" is receiving the value. Then I tried:

function newPage(p_id){
    var id = p_id;

    switch(id){
        case 1:
            $("#div").load("content.php?id=1");
            break;
        case 2:
            $("#div").load("content.php?id=1");
            break;
        default:
            alert("Default");
            break;
    }
}

In this case the default is executed even if the value of id is 1 or 2.

Where am I going wrong?

Was it helpful?

Solution

You need this -

$("#div").load("content.php?id="+id);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top