开发者

How to call switch function from using PHP

I have a ajax.php file that contains the following sample code:

switch($_REQUEST['request_name'])
    {
        case '开发者_如何学编程edit':
           echo "edit mode";
           break;
        case 'delete':
           echo "delete mode";
           break;
        default:
           die("Error: wrong request name ".$_REQUEST['request_name']);
           break;
    }

I have another file index.php that I want to call results from ajax.php. Hmm.. how do I do it? I normally use javascript to call results from ajax.php. But is there a way I can call results from within index.php as well? Code is wrong below but something to this effect.

$result = include("ajax.php?request_name=delete");
echo $result;


You were correct to use include but instead of passing in the vars like a query string you can just define them before your include and they'll be brought in to the file.

$_REQUEST['request_name'] = 'edit';
include('ajax.php');

Any variables that are then defined in your included file will now be available in the parent file as well. If you were to process the edit action and store the results in a var called $results in ajax.php you would have access to that same variable from within the including file (after the include statement).

$_REQUEST['request_name'] = 'edit';
include('ajax.php');
echo $results;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜