sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [WEBDIALOG] getJSON from source folder

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 3 Posters 641 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jolranJ Offline
      jolran
      last edited by

      Hi.

      (this topic is related to NODE-GUI development BTW..)

      Been fiddeling with Jquery getJSON a little and have some quiries.

      I have quite a large configuration data that needs to be hardcoded.
      Basically info concering each node that cannot be created
      dynamically.

      Normally I suppose I could just store it into a simple JS object, but during a session
      it is not likely all nodes from that library would get used. There could be hundreds+!
      So it seams like waste of energy for the browser caching all that..

      So I tried to store a config.json in the source folder and use
      Jquery.getJSON() and it seams to be working fine. Something like:

      
      $.ajaxSetup({ cache;false });//prevent from caching the whole file
      $.getJSON("JSON/myjson.json", function(data){ 
      
        // traverse data here and store in variable or whatever..
      
      }
      
      

      Now off course I'm wondering if this is a safe way off doing things or could run
      into browser specific trouble or security_policy breaches. I don't think I'm violating
      the same origin policy?
      Been googeling the subject quite hard but doing this is in Sketchup and it's enviroment
      is so specific it's quite hard to relate.

      Maybe I'm overcomplicating this. Just store that damn thing in a object ๐Ÿ˜„

      NOTE: I'm only Reading the JSON, not storing any data.
      Also I have considered the issue of error check for valid JSON.

      1 Reply Last reply Reply Quote 0
      • A Offline
        Aerilius
        last edited by

        For local files it behaves sometimes different. (I also ran into similar issues, and got it working but now it isn't working anymore. I'll look it up and post back.)
        Since JSON is also JavaScript, are there any reasons why you couldn't load it as .js file? Create a <script> element with scr="JSON/myjson.js" and attach it to document.

        1 Reply Last reply Reply Quote 0
        • jolranJ Offline
          jolran
          last edited by

          Hi Aerilius!

          @unknownuser said:

          during a session
          it is not likely all nodes from that library would get used. There could be hundreds+!
          So it seams like waste of energy for the browser caching all that..

          Like I said, there is no problem having it in a separate JS or even in the main js file.

          I just thought I could get better performance that way, by not loading in the static configuration data unless requested for.
          If keeping it in the js there would be no need to use JSON though..

          There will be many Icons and SVG curve rendering so it all will add up. At the moment the GUI is not swamped with stuff so I can't really see the performance hit as it will get. Maybe I'm just over complicating the matter..
          As usual the big bottleneck will probably be in SU somewhere..

          @unknownuser said:

          For local files it behaves sometimes different. (I also ran into similar issues, and got it working but now it isn't working anymore. I'll look it up and post back.)

          Ahh. OK.. It's working for me though right now. Are you also writing?
          I'm just interrested in reading files.

          If there are any issues I'll just dump the idea, no biggies..

          Thanks for the help, appreciate it!

          edit: Btw might mention that I'm creating this JSON file myself, so there isen't a dependancy for a framwork or anything like that..

          Looking forward to your ideas on the matter, AE ๐Ÿ˜„

          1 Reply Last reply Reply Quote 0
          • A Offline
            Aerilius
            last edited by

            I meant "create the script element dynamically" (only on demand). Not sure if you understood it like thatโ€ฆ

            1 Reply Last reply Reply Quote 0
            • jolranJ Offline
              jolran
              last edited by

              No. I did not understand it like that, and I still don't not know what you mean by "loading script element dynamically" and scr="JSON/myjson.js".

              That would cache the whole file loading it in the first time anyway, no?

              I'm sure your thinking of something more cleverly then I, so exuze me if I sound off. ๐Ÿ˜„

              I don't consider this being a problem, more of an interesting solution if I can have it working properly..

              edit: you mean with "document.write". That's seams to be sketchy.?

              1 Reply Last reply Reply Quote 0
              • jolranJ Offline
                jolran
                last edited by

                I'm setting this aside for the moment. Getting errors in crome debugger.

                "Origin null is not allowed by Access-Control-Allow-Origin."

                Crome has reputation being very hard on applying the "Same Origin Policy" to local files.

                But this still indicates that it could cause trouble for me later on..

                1 Reply Last reply Reply Quote 0
                • tt_suT Offline
                  tt_su
                  last edited by

                  For ajax calls you need to use JSONP to avoid XSS blocking.

                  1 Reply Last reply Reply Quote 0
                  • jolranJ Offline
                    jolran
                    last edited by

                    JSONPadding โ˜€ Will try that.
                    Thanks a lot!

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement