javascript - can i use a function than making new php page when ajax POST/GET is called? -
using diiferent php page delete/insert/update every module make make php page every ajax call.
$.post("../lib/ajax/edit-user-save.php",{username:username,email:email,id:id},function(data){} i use edit-user-save.php edit module. delete make delete-user.php. cant use function call when making post/get ajax request instead of redirecting php page?
your suggestion appreciated. : d
if seems stupid question m extremly sorry : 3
just pass parameter action you're trying use, check parameter on server side , call appropriate function. this:
client side:
$.post("../lib/ajax/user.php", { username: username, email: email, id: id, action: 'edit' }, function(data){}); server side:
switch($_post['action']) { case 'edit': die(edit()); case 'delete': die(delete()); } or fancy on server-side , this:
if (function_exists($_request['action'])) { die($_request['action']()); } this check see if function exists on server-side page , if does, call it. warning: allow user call php function available script, if there functions shouldn't able call, you'll have either whitelist ones can call or blacklist ones can't.
the die() calls stop script execution once function call returns, preventing script continuing , re-generating html.
Comments
Post a Comment