Search code examples
phpjqueryurlswitch-statementjquery-load

Passing an http query string with jquery


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?


Solution

  • You need this -

    $("#div").load("content.php?id="+id);