views:

262

answers:

1

Hello,

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

+1  A: 

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

Ben Sykes
LOL it happens to all of us, like trying to back out of a room in a FPS game after the 6 players in there shot you already :)
Mark Schultheiss
uncaught exception: Syntax error, unrecognized expression: # is what I get??
Richard
@Mark, just caught this error, when I try to load it in firebug
Richard
As a test, change the +rpc to #div02 in the string, - suspect the function is not returning a data object myself: load( url, [data], [callback] )
Mark Schultheiss
I have a similar sample working here so doesn't seem to be a variable scope thing?Sample code:$(document).ready(function(){ var test = 'div02'; $("#something").load("/testbed/test.html #"+test, function(){alert('test');}); });
Ben Sykes
jaminute, I will give the complete function
Richard
Your $.ajax() function is returning AFTER your load function - put your load function into the success function of $.ajax
Ben Sykes
yes, I noticed too, I put an alert between those too, and that one returned first. I should be alright now. Everything ok, thanks @Ben,@Mark
Richard