Richard
Richard

Reputation: 4546

jquery load a selector contained in a variable

Can anyone help me with the right syntax to load some div, please

I try'd to concat it in several ways, except the right way

rcp= "#div02";
$("#content").load("/inc/forms.php " +rcp'"', function(){....

I will keep trying in the meantime

EDIT

AND ACCIDENTLY GOT IT RIGHT (not completely yet)

$("#content").load("/inc/forms.php #" +rcp, function(){.... is ok

BUT before the load function the ajax function is called, and returns with the rcp variable I think now it is a variable scope problem. I already try'd setting a global rpc variable, but it's not working, not yet anyway!

var avp ='';

$("a.order").click(function(e){
e.preventDefault();

$.ajax({
url: "/order/request",
cache: false,
type: "POST",
dataType: "json",
timeout: 5000,
success: function(data)
{
if(data.check){         //ingelogd??


    avp = data.requestpage.avp;
}

}//EINDE success

});//EINDE ajax


$("#content").load("/inc/forms.php #"+avp, function()                                                       
});//EINDE LOAD

});

thanks in adv, Richard

Upvotes: 0

Views: 1209

Answers (1)

Ben Sykes
Ben Sykes

Reputation: 56

You seem to have an extra " character appending there for some reason which isn't needed and is probably making it try to find the selector actually called div02"

rcp= "div02";
$("#content").load("/inc/forms.php #" +rcp+'"', function(){....

Change that to

    rcp= "div02";
$("#content").load("/inc/forms.php #" +rcp, function(){....

Edit:

Your $.ajax() function is returning AFTER your load function - put your load function into the success function of $.ajax

Upvotes: 1

Related Questions