1

I have this code tested in w3school

    <!DOCTYPE html>
<html>
<head>

</head>
<body>

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>

<b>Books</b>

<br>

Author<br>
<div id="author"></div>
<br>


<script>
var getvar = "books.xml";

$( "#author" ).load("books.xml author");


</script>
</body>
</html>

This is working... now I need to replace the books.xml with the variable getvar

This code is not working

    <script>
var getvar = "books.xml";

$( "#author" ).load("getvar author");


</script>

Any help how to replace with the getvar variable?

1 Answer 1

2

You need to update your code from

$( "#author" ).load("getvar author");

to

$( "#author" ).load(getvar + " author");

Additionally, move your script inside document ready block.

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

5 Comments

I tried that but it didn't work. Got this message - 504 - Gateway Timeout
The above should have worked. You should also move your script inside the the document ready block.
@syntaxcode - Apologies but not clear with your comment on head tag
For some reason, when I placed the script into the head and followed your code, then it worked.
The above code will work fine even when you place your script in body tag. However, as I mentioned, you should move your script inside document ready block. For reference - learn.jquery.com/using-jquery-core/document-ready

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.