您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

js如何调用php函数

2024/4/5 12:06:33发布20次查看
js调用php函数的方法:
jquery.ajax({ type: "post", url: 'your_functions_address.php', datatype: 'json', data: {functionname: 'add', arguments: [1, 2]}, success: function (obj, textstatus) { if( !('error' in obj) ) { yourvariable = obj.result; } else { console.log(obj.error); } }});
您的_function_address.php如下所示:
<?php header('content-type: application/json'); $aresult = array(); if( !isset($_post['functionname']) ) { $aresult['error'] = 'no function name!'; } if( !isset($_post['arguments']) ) { $aresult['error'] = 'no function arguments!'; } if( !isset($aresult['error']) ) { switch($_post['functionname']) { case 'add': if( !is_array($_post['arguments']) || (count($_post['arguments']) < 2) ) { $aresult['error'] = 'error in arguments!'; } else { $aresult['result'] = add(floatval($_post['arguments'][0]), floatval($_post['arguments'][1])); } break; default: $aresult['error'] = 'not found function '.$_post['functionname'].'!'; break; } } echo json_encode($aresult);?>
推荐:php服务器
以上就是js如何调用php函数的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product