Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Ajax

Bastian

Villager
Xy$
0.00
I was wobdering if anyone of y'all new if ajax is going to be included in the js library, or if we needed to include our own, and how much of a hassle that's going to be?

I'm going to make some some sort of platform, where you can fight your friends, trade items and chat with them, and include a feature where friends can explore parts of your world, since I'm planning to make parts of it modular!
 

Tsukihime

Praised Adventurer
Xy$
0.00
This is the kind of logic they're using to send requests

Code:
var xhr = new XMLHttpRequest();
  try {
      xhr.open('GET', lastScript.src);
      xhr.overrideMimeType('text/javascript');
      xhr.send();
      return true
  } catch (e) {
      return false
  }
So you'll likely need to include an AJAX library...
 

Tsukihime

Praised Adventurer
Xy$
0.00
Sorry, I was wrong.
Scripts aren't loaded asynchronously but other resources are.

Code:
   WebAudio.prototype._load = function(url) {
    if (WebAudio._context) {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', url);
        xhr.responseType = 'arraybuffer';
        xhr.onload = function() {
            if (xhr.status < 400) {
                this._onXhrLoad(xhr)
            }
        }.bind(this);
        xhr.onerror = function() {
            this._hasError = true
        }.bind(this);
        xhr.send()
    }
};
So ya, you can do AJAX pretty easily.

If you don't like working with xhr directly you might grab any library that wraps it or something.
 

cav_dan

Towns Guard
Remember that AJAX calls should not be cross-domain (another address outside your server), for security reasons. Well, at least if you're running on the browser.
 
Top