Results 1 to 2 of 2

Thread: call a json file with a value selection

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    1

    call a json file with a value selection

    Hi everybody, i'm a new user of webGl and while i was working i found this interesting and tried to do but it doesn't work.

    well this is my question:

    I have this part of code i think that the calling is correct, the first time i load the page it uses to appear the image selected by default but when i select the other image this doesn't appear, besides the default image never change (disappear or something so ) that makes me think that the call is not even working.

    Maybe i have to create another method or something like that? another kind of call? or i am forgetting something?

    in my list i have two options exactly 1 and 2.
    i based on the calling for textures that works well.

    function x() {
    var obj = document.getElementById("objs").value;

    if (obj == "1") {
    var request = new XMLHttpRequest();
    request.open("GET", "obj1.json");
    request.onreadystatechange = function () {
    if (request.readyState == 4) {
    handleLoadedTeapot(JSON.parse(request.responseText ));
    }
    }


    request.send();

    } else if (obj == "2") {
    var request = new XMLHttpRequest();
    request.open("GET", "obj2.json");
    request.onreadystatechange = function () {
    if (request.readyState == 4) {
    handleLoadedTeapot(JSON.parse(request.responseText ));
    }
    }
    request.send();
    }
    }


    If you know another method for calling different json files in the same window or give me an idea of what should i do i would thank you.
    bye.

  2. #2
    Junior Member
    Join Date
    Sep 2012
    Posts
    3

    Re: call a json file with a value selection

    This is from emoller webgl-utilities located https://github.com/emoller/WebGL101/blo ... l-utils.js
    He has many webgl code resources.

    function loadFile(file, callback, noCache, isJson) {
    var request = new XMLHttpRequest();
    request.onreadystatechange = function() {
    if (request.readyState == 1) {
    if (isJson) {
    request.overrideMimeType('application/json');
    }
    request.send();
    } else if (request.readyState == 4) {
    if (request.status == 200) {
    callback(request.responseText);
    } else if (request.status == 404) {
    throw 'File "' + file + '" does not exist.';
    } else {
    throw 'XHR error ' + request.status + '.';
    }
    }
    };
    var url = file;
    if (noCache) {
    url += '?' + (new Date()).getTime();
    }
    request.open('GET', url, true);
    }

Similar Threads

  1. Call OpenCL functions from another file
    By youli13 in forum OpenCL
    Replies: 1
    Last Post: 09-16-2012, 04:48 PM
  2. Why does EGL call glGetIntegerv when I call wglSwapBuffer?
    By teriba in forum Cross API and window system integration
    Replies: 0
    Last Post: 07-23-2009, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •