re1man
re1man

Reputation: 2367

having problems passing javascript variable to php file in the url

I have this code right now :

$(document).ready(function() {
var ktitle =        $('.hiddentwo').text();
$('div#tab2').load('morefour.php?title=ktitle');
});  

but the php file doesn't seem to be getting this variable...am I doing something wrong?

I echo something in the php file and I see the text. Also when I echo the $ktitle in the php file I get 'kitle'...that should not be happening :p. This is a stupid question, but I just want to know how to store that variable in the url.

Upvotes: 0

Views: 71

Answers (3)

Kanishka Panamaldeniya
Kanishka Panamaldeniya

Reputation: 17576

try using

   $('div#tab2').load("morefour.php", {
       title:ktitle
   });

or

$('div#tab2').load('morefour.php?title='+ktitle);

UPDATE

In the first case, the data are passed to the script via POST, in the second via GET.

Upvotes: 3

Tomalak
Tomalak

Reputation: 338208

$('div#tab2').load( 'morefour.php?title=' + encodeURIComponent(ktitle) );

Upvotes: 3

deceze
deceze

Reputation: 522081

Because you're hardcoding the ?title to "ktitle". If you want to replace this with a variable, you need to concatenate the variable with 'morefour.php?title=' + ktitle.

Upvotes: 1

Related Questions