javascript - var = Variable + 'String' -


i'm trying dynamically include text file page using jquery, can't seem work variable filepath. tried title.txt instead of passing variable , worked, $title + '.txt' didn't work.

what doing wrong?

works:

$(function () {       $("#list").load('test.txt'); }); 

attempt 1:

$(function () {     var $title = document.getelementsbytagname("title")[0].innerhtml,         $url = $title + '.txt';      $("#list").load($url); }); 

attempt 2:

$(function () {     var $title = document.getelementsbytagname("title")[0].innerhtml,         $ext = '.txt',         $url = $title + $ext;      $("#list").load($url); }); 

attempt 3:

$(function () {     var $title = document.getelementsbytagname("title")[0].innerhtml,      $("#list").load($title + '.txt'); }); 

try this, per comment in chat:

$(function () {     var $title = encodeuri( $('title').text() ),          $url = $title + '.txt';      $("#list").load($url); }); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -