1

I have an object defined in a .js file, which is done via PHP on the server side.

I would like to know how to set a variable equal to this object, because the JS file doesn't actually define anything, it is just the object...

EX: (this is my .js file on my server)

{  
"Title": {"Link" = "http://example.com", "img" = "http://imgurl.com"},
 "Title2": {"Link" = "http://blahblah.com", "img" = "http://imgurl.com"}
}

1 Answer 1

1

This is what we call a JSON file. You can parse it with JSON.parse.

As for how to get the content of the file dynamically, you could use the JQuery function getJSON or work the AJAX yourself, but I don't know a lot about that.

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

4 Comments

If it is stored on my server as a .js, how could I download it and parse it? Alright thanks, ill try it :)
I've edited my answer. Since you didn't tag that question JQuery though, I guess it wont help.
I know a bit about jqery, it should work for what I'm trying to do. Thanks!
Glad to help! I've also found this other question, might be helpful: stackoverflow.com/questions/9838812/…

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.