fmihel / ajax
Apache/PHP服务器的ajax响应器
v1.1.1
2024-01-25 08:59 UTC
Requires
README
安装
$ npm i fmihel-ajax $ composer require fmihel/ajax
运行脚本以从vendor路径中删除js文件
$ cd ./vendor/fmihel/ajax && ./composer-after-install.sh && cd ../../../
简单用法
文件结构
path
|-path1
| |-path2
| |-mod.php
|-index.php
|-client.js
client.js
import ajax from 'fmihel-ajax'; ajax::send({ to:'path1/path2/mod', data:{ msg: 'send msg to server',any_num:10,arr:[1,32,4,2]}, }) .then(data=>{ console.info(data); }) .catch(e=>{ console.error(e); });
mod.php
位于<path-of-index.php>/path1/path2
目录中
<?php use fmihel\ajax\ajax; error_log(print_r(ajax::$data,true)); ajax::out('hi, from server'); ?>
index.php
<?php require_once __DIR__.'/vendor/autoload.php'; use fmihel\ajax\ajax; if (ajax::enabled()){ ajax::init(); require_once ajax::module(); ajax::done(); }; ?>