Jump to content

How to Store JSON array and run it correctly


Mudsaf

Recommended Posts

Hello, i'm wondering how to store JSON array as javascript variable or something so visitor doesn't have to reload the file all the time.

 

Method getting JSON

<script>$(function() {$.getJSON('<myfolder/filename.js>', function(<something>) { /* store <something> */});});</script>

"so visitor doesn't have to reload the file all the time", that was badly told. I mean if the script runs more than once at same page.

Edited by Mudsaf
Link to comment
Share on other sites

 

var response = null; function getStuff(){  if(!response){    $.getJSON('path/to/file', function(data){      response = data;    })  }   return response;}
Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...