hikari-no-yume / PictoSwap

Clone of Nintendo Letter Box/Swapnote for the Nintendo 3DS web browser
http://pictoswap.ajf.me/
Other
19 stars 3 forks source link

Boilerplate XMLHttpRequest code should probably be made into a function #15

Closed hikari-no-yume closed 9 years ago

hikari-no-yume commented 9 years ago

Would follow the Don't Repeat Yourself principle. Could also make for a nicer API, something like this:

postRequest(SID, {
    action: 'foobar',
    ...
}, function (result) {
    // success!
    ...
}, function (error) {
    // failure!
    ...
});

No need to specify the URL, everything goes to /api.php after all.

You could have a similar function for GET requests as for POST requests, it'd just URL encode the parameters rather than sending them as a JSON body.

hikari-no-yume commented 9 years ago

Done by https://github.com/TazeTSchnitzel/PictoSwap/commit/dc5cbb54e96da8a9ce5938290e3be6ba6b0e771d