0

How can i put variable into "load" function ? - i need to recover source filename and put in location

function updateClock() {
    var loc = $(location).attr('pathname');
    // $("#clock").load('index.php #clock');  <- this one is working but I need variable 
    $("#clock").load('$loc #clock'); < -problem with $loc variable(how to implement)
}

$(document).ready(function() {
    setInterval('updateClock()', 1000);
});

2 Answers 2

1

If you put your variable in string value like

$("#clock").load('$loc #clock');

interpreter thinks that as a string.. so put it outside and make it like...

$("#clock").load(loc + ' ' + '#clock');

that should work.

Sign up to request clarification or add additional context in comments.

2 Comments

Already tried this way but it doesn't work but the idea is good. The solution is : $("#clock").load(loc + ' ' + '#clock'); Thanks !
So check for loc value with console.log(loc); in proper place. Maybe it is undefined by your code.
0

With help from user "tanaydin", the solution is :

$("#clock").load(loc + ' ' + '#clock');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.