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开发者_StackOverflow社区 happening :p. This is a stupid question, but I just want to know how to store that variable in the url.
$('div#tab2').load( 'morefour.php?title=' + encodeURIComponent(ktitle) );
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.
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
.
精彩评论