Plugin Name: Simple Ajax
Version: 1
Author: Amy Pond @ www.hbgames.org
Introduction
As RPG Maker MV games use JavaScript, one simple way to talk to a server is via the web, using Ajax. Technically here we aren't using the x part unless we format the responded text using XML, but the principle is the same.
This plugin is one simple function that returns a text variable from a web server using some entered variables.
How to Use
Create a PHP file on your web server which returns a text response (using echo() for example). Use GET variables to generate the response based on data sent to it.
There is an example PHP file in the Help part of the plugin.
Install the plugin, and type in the location of your PHP file, for example:
http://www.rpgmakerweb.com/files/ajax.php (not a real file).
As an example of its usage:
var mytext = ajaxRequest("variable=1&othervariable=2");
On the server we check for $_GET['variable'] and $_GET['othervariable'].
We clean the variables before using (this is very important - please read up on cleaning user sent data in PHP).
Then we do something with these variables and send back some data. Say we echo("hello"), then:
var mytext = ajaxRequest("variable=1&othervariable=2"); // mytext = "hello"
Code:
Credits/thanks
By Amy Pond of
www.hbgames.org and originally created for the game Afar.
Thanks to w3schools.
Terms of Use
Free for use in any game with no credit necessary. If you
like you can provide a link to HBGames.org or this thread but this is not necessary. Available for commercial games for free.
Please note that this script used incorrectly creates a vulnerable web server. If you do not clean your GET variables then you ARE open to hacking quite easily. No liability is accepted for any damage caused by use of this function. Use is at your own risk and I urge you to look into PHP security, in particular, cleaning data sent from a user. For integers this can be as simple as turning them into integer variables by (int)var, though for text you will need prewritten functions, or to make your own using preg_replace.
本贴来自国际rpgmaker官方论坛作者:Ellie Jane处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/simple-ajax-request-data-from-a-web-server.48720/